7 ms·
K-Means Clustering is one of those tools that once you understand it becomes more and more useful over time. You keep finding new ways to apply it, it's a bit l
by jacquesm 5y ago
K-Means Clustering is one of those tools that once you understand it becomes more and more useful over time. You keep finding new ways to apply it, it's a bit like Quicksort, Bresenham or Divide and Conquer in that sense.
- csunbird 5y agoIt is also super intuitive. The logic makes sense immediately when you see it first time.
- NicoJuicy 5y agoI'd be interested to hear some of those examples actually, i know what it is. But I haven't used it in practise ( yet).
- jacquesm 5y agoJust one example from recent practice, to automatically collect a number of texts (pdfs) into a set of groups for easier subsequent processing (summarization). Without K-Means you'd have a pretty hard time figuring out for each subsequent document which group you want to add it to or whether or not you need to make a new group. With K-Means given a fairly simple 'distance' function all of the grouping is automatic. In fact, once you have K-Means coded up the distance function is the problem to solve. If you can't meaningfully define a distance then you probably won't be able to use it.
- nerdponx 5y agoThis is probably the biggest (only?) advantage of k-means in real problems: it's easy to put new data points into existing clusters. You can do this with mean-shift clustering as well. It's not obvious how to do this with HDBSCAN or hierarchical clustering. Maybe you'd have to draw some kind of boundary around each cluster after fixing the parameters.
- anonymousDan 5y agoYou mean to update the clusters incrementally as new data arrives?
- NicoJuicy 5y agoDo you have an example of the groups ( = output) and what you are using as variables for input ? Eg. Wouldn't KNN be easier if you want to classify new groups later on? I'm probably missing something, but defining the groups upfront seems more labor intensive ( note: novice in this area )
- dilyevsky 5y agoNot tp but I’ve tried using k-means for similar task and and LDA and found LDA to be better. Particularly if your documents have mixture of topics
- jacquesm 5y agoWell, you don't so much define the groups up front as that you define the number of groups up front, the distance function is what will eventually result in the mapping of inputs to groups if you use the groups (for instance: sample texts in those groups) as a part of the scoring system.
- flashfaffe2 5y agoDepending on the task but using K- means implies you have have idea of the clusters you might have ( unsupervised learning). KNN assumes the groups already exist.
- importantbrian 5y agoInteresting did you try any other techniques like HDBSCAN? I've found HDBSCAN to produce more meaningful clusters for a similar workflow.
- Helmut10001 5y agoWorking in spatial data science, I rarely find applications where k-means is the best tool. The problem is that it is difficult to know how many clusters you can expect on maps. Is it 5; 500; or 10,000? Here HDBSCAN [1] shines because it will cluster _and_ select the most suitable number of clusters, to cut the single linkage cluster tree. [1]: https://github.com/scikit-learn-contrib/hdbscan https://github.com/scikit-learn-contrib/hdbscan
- jacquesm 5y agoYes that is a good point, if you don't have a good idea on how many subdivisions you want then K-Means won't help you and hdbscan is better. I always liken the latter to 'automatic feature detection'.
- falkenb0t 5y agoI found myself having to do some clustering a few months back and learned about mean-shift clustering [1]. I found it to be a nice clustering algorithm for when you don't know quantity of clusters ahead of time. That said, its worth noting that there are algorithms out there for determining optimal number of clusters for k-means (though personally I found them to be costly and subject to overfitting) like using the silhouette coefficient or elbow method [2]. [1]: https://www.geeksforgeeks.org/ml-mean-shift-clustering/ https://www.geeksforgeeks.org/ml-mean-shift-clustering/ [2]: https://towardsdatascience.com/k-means-clustering-how-it-works-finding-the-optimum-number-of-clusters-in-the-data-13d18739255c https://towardsdatascience.com/k-means-clustering-how-it-wor...
- nerdponx 5y agoNote also that specifically for one-dimensional data, there is a globally optimal solution to the k-means clustering problem. There is an R package that implements it using a C++ core implementation [1], and also a Python wrapper [2]. This implementation is also surprisingly fast, so you can use it to brute-force check many different numbers of clusters and check using silhouette distance. The advantage over traditional k-means is that you don't need to check multiple initializations for any given number of clusters, because the algorithm is deterministic and guaranteed to find the global optimum. [1]: https://cran.r-project.org/package=Ckmeans.1d.dp https://cran.r-project.org/package=Ckmeans.1d.dp [2]: https://github.com/djdt/ckwrap https://github.com/djdt/ckwrap
- time_to_smile 5y agoMy experience has been the opposite, K-Means clustering is generally pretty useless in the real world with real data. In general clustering algorithms tend not to be very useful because they are ultimately just very poorly defined latent variable models. Most people starting out with clustering don't even understand that they're making the assumption that K latent variables are responsible for generating the observed data. K-means in particular has loads of problems for practical applications: the final location of the means is heavily dependent on the initial locations, the final location can also be heavily dependent on the particular dataset used (try bootstrap resampling to get variance of your means), assumes the data rests on a Euclidean surface, making geometric assumptions about high dimensional spaces is almost always a bad a bad idea (things being close by in Euclidean terms in high dimensional spaces often misses things that are nearly identical except on feature that is quite different). With over a decade of modeling experience and building data science products I have never seen a product ship that relies on k-means and never seen analysis that isn't coming form someone junior in the field that relies on it. K-means is a great demo the expectation maximization algorithm, which is a useful tool to understand, but generally I would avoid k-means, and clustering in general unless you have an explicit understanding of why you are doing it. Even then, there is probably a more stable and appropriate latent variable model you could use.
- nerdponx 5y ago> With over a decade of modeling experience and building data science products I have never seen a product ship that relies on k-means and never seen analysis that isn't coming form someone junior in the field that relies on it. I used it exactly once, and it worked quite well :) But that was because I was clustering 1-dimensional data, which has a globally-optimal solution and there was a fast implementation for it available (see my post https://news.ycombinator.com/item?id=30675594 https://news.ycombinator.com/item?id=30675594). So it was okay in that instance to brute-force check a lot of different cluster numbers and then post-process the results with some heuristics.
- orange3xchicken 5y agoI think K is usually interpreted as the # of gaussians from which the data has been assumed to be sampled. Not immediately related to # of latent variables unless you invoke kernel kmeans or something like laplacian eigenmaps/diffusion maps.