array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
target_names
array(['setosa', 'versicolor', 'virginica'], dtype='<U10')
小试一下 from sklearn.cluster import KMeans # 聚类包 from sklearn.preprocessing import StandardScaler, MinMaxScaler # 预处理包 # 标准差标准化 # 公式:(x-mean(X))/std(X) scale = StandarScaler().fit(data) # 训练规则 X = scale.transform(data) # 应用规则 # 离差标准化(零一标准化) # 公式:(x-min(X))/(max(X)-min(X)) scale = MinMaxScaler().fit(data) # 训练规则 X = scale.transform(data) # 应用规则 X clf = KMeans(n_clusters = 3, random_state = 123).fit(X) # 聚成3类 clf.labels_ kmeans = KMeans(n_clusters = 3, random_state = 123).fit(data) # 用data对比一下 kmeans.labels_