我已经将三个特征Feature1、Feature2和Feature3聚类,并得到了两个簇。我正在尝试使用matplotlib可视化一个三维簇。
在下表中,执行聚类的特征有三个。簇的数量为2。
Feature1 Feature2 Feature3 ClusterIndex
0 1.349656e-09 1.000000 1.090542e-09 0
1 1.029752e-07 1.000000 6.040669e-08 0
2 2.311729e-07 1.000000 1.568289e-11 0
3 1.455860e-08 6.05e-08 1.000000 1
4 3.095807e-07 2.07e-07 1.000000 1
尝试了这段代码:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.array(df['Feature1'])
y = np.array(df['Feature2'])
z = np.array(df['Feature3'])
ax.scatter(x,y,z, marker=colormap[kmeans.labels_], s=40)
然而,我遇到了错误"ValueError: could not convert string to float: red"
。因此,标记部分是我遇到错误的地方。
通过在散点图中绘制点并使用聚类标签进行区分,可以很容易地进行集群的二维可视化。
只是想知道是否有一种方法可以进行三维集群可视化。
任何建议都将不胜感激!!
colormap
是什么,kmeans.labels_
又是什么呢? - ImportanceOfBeingErnest