Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scikit-learn's k-means: what does the predict method really do?

When I use scikit-learn's implementation of k-means I usually just call the fit() method and that is enough to get the cluster centers and the labels. The predict() method is used to calculate the labels and even a fit_predict() method is available for convenience, but if I can get the labels only using fit(), what is the purpose of the predict() method?

like image 288
c_david Avatar asked Jul 29 '14 09:07

c_david


Video Answer


1 Answers

predict, as @EdChum suggested, can be used on unseen data. This (and more so, the transform method) is useful when k-means is used for feature extraction in semisupervised learning: you cluster a large set of samples, then use nearest centroid/distance to centroids as features for a subsequent supervised learning problem. When using the result for prediction, you get samples that were not seen by k-means.

like image 71
Fred Foo Avatar answered Oct 04 '22 12:10

Fred Foo