Skip to content

Instantly share code, notes, and snippets.

@spikar
Created May 31, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spikar/8da8cf7ab42de8d4fe460c6ecbe1ab52 to your computer and use it in GitHub Desktop.
Save spikar/8da8cf7ab42de8d4fe460c6ecbe1ab52 to your computer and use it in GitHub Desktop.
from sklearn.cluster import KMeans
# Number of clusters
kmeans = KMeans(n_clusters=k)
# Fitting the input data
kmeans = kmeans.fit(X)
# Getting the cluster labels
labels = kmeans.predict(X)
# Centroid values
centroids = kmeans.cluster_centers_
# Comparing with scikit-learn centroids
print(C) # From Scratch
print(centroids) # From sci-kit learn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment