鸢尾花完整数据做聚类并用散点图显示.
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()