Tutorial For K Means Clustering in Python Sklearn - MLK - Machine Learning Knowledge-3
Tutorial For K Means Clustering in Python Sklearn - MLK - Machine Learning Knowledge-3
0 -0.192221 0.319683
1 -0.458175 -0.018152
2 0.052562 0.551854
3 -0.402357 -0.014239
4 -0.031648 0.155578
K=range(2,12)
wss = []
for k in K:
kmeans=cluster.KMeans(n_clusters=k)
kmeans=kmeans.fit(pca_df)
wss_iter = kmeans.inertia_
wss.append(wss_iter)
In [17]:
plt.xlabel('K')
plt.ylabel('Within-Cluster-Sum of Squared Errors (WSS)')
plt.plot(K,wss)
Out[17]:
···
In[18]:
labels=cluster.KMeans(n_clusters=i,random_state=200).fit(pca_df).labels_
print ("Silhouette score for k(clusters) = "+str(i)+" is "
+str(metrics.silhouette_score(pca_df,labels,metric="euclidean",sample_siz
Out[18]: