import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import load_iris

iris=load_iris()
X=iris.data
print(X)

from sklearn.cluster import KMeans

est=KMeans(n_clusters=3)
est.fit(X)
kc=est.cluster_centers_
y_kmeans=est.predict(X)

print(y_kmeans,kc)
print(kc.shape,y_kmeans.shape,X.shape)
plt.scatter(X[:,0],X[:,1],c=y_kmeans,s=50,cmap=\'rainbow\');
plt.show()

 

版权声明:本文为zwlh原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zwlh/p/9852625.html