瑞士卷聚类 from mpl_toolkits.mplot3d import Axes3D from sklearn.cluster import KMeans from sklearn import manifold, datasets import matplotlib.pyplot as plt #生成带噪声的瑞士卷数据集 X,color = datasets.samples_generator.mak
瑞士卷聚类
from mpl_toolkits.mplot3d import Axes3D from sklearn.cluster import KMeans from sklearn import manifold, datasets import matplotlib.pyplot as plt
#生成带噪声的瑞士卷数据集 X,color = datasets.samples_generator.make_swiss_roll(n_samples=1500)
#使用100个K-means簇对数据进行近似 clusters_swiss_roll = KMeans(n_clusters=100,random_state=1).fit_predict(X)
fig2 = plt.figure() ax = fig2.add_subplot(111,projection=‘3d‘) ax.scatter(X[:,0],X[:,1],X[:,2],c = clusters_swiss_roll,cmap = ‘Spectral‘)
plt.show()