Last active
October 9, 2017 18:48
-
-
Save manvillej/fbaf0e8f3e442241be868b3ca43c57bc to your computer and use it in GitHub Desktop.
Short Kmeans Example from Sklearn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.cluster import KMeans | |
K=3 # number of clusers | |
# setting random_state to 0 seeds random number generate to get | |
# the same results every run. X is the a MxN matrix where N is the number of features | |
# and M is the number of examples. | |
kmeans = KMeans(n_clusters=K, random_state=0).fit(X) | |
# location of centroids | |
centroids = kmeans.cluster_centers_ | |
# labels for each example, an Mx1 matrix | |
idx = kmeans.labels_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment