【发布时间】:2020-09-08 15:43:07
【问题描述】:
我有一个像这样的数据集:
0 1 2 3 4 5
Unnamed: 0 X Y Z L a b
green leaf 15.4999 20.9143 8.15938 52.8556 -23.6196 34.4027
yellow flower 38.4721 41.3847 4.41641 70.4446 -2.74272 80.3299
green leaf 8.42304 10.2697 4.58244 38.3222 -11.2275 24.0959
yellow flower 59.1535 65.6835 42.2067 84.8347 -7.73898 28.0364
我使用 L,a,b 列来预测集群分配,并得到结果-y_pred like :
[1 2 1 1 ...]
但是,我想要下面的结果 -
cluster1: green leaf, green leaf, yellow flower
cluster2: yellow flower
我使用的代码是:
df = np.transpose(pd.read_excel('color_xyz_lab.xlsx'))
val_all = np.array(df.values[1:,:], dtype=np.float64)
val_lab = val_all[:,3:6]
y_pred = KMeans(n_clusters= 4 , random_state=0).fit_predict(val_lab)
【问题讨论】:
标签: python python-3.x pandas numpy scikit-learn