Skip to content

Instantly share code, notes, and snippets.

@ImadDabbura
Created September 17, 2018 16:51
Show Gist options
  • Select an option

  • Save ImadDabbura/3c7621d74b380e902aa836f74d859ce9 to your computer and use it in GitHub Desktop.

Select an option

Save ImadDabbura/3c7621d74b380e902aa836f74d859ce9 to your computer and use it in GitHub Desktop.
# Run the Kmeans algorithm and get the index of data points clusters
sse = []
list_k = list(range(1, 10))
for k in list_k:
km = KMeans(n_clusters=k)
km.fit(X_std)
sse.append(km.inertia_)
# Plot sse against k
plt.figure(figsize=(6, 6))
plt.plot(list_k, sse, '-o')
plt.xlabel(r'Number of clusters *k*')
plt.ylabel('Sum of squared distance');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment