你好,我正在处理winkosisn乳腺癌数据集。我已经对它应用了主成分分析,并将结果存储在df1中。df2包含应用KMeans时获取的类类型的标签。然后我将df1和df2连接起来。
为了可视化结果,我使用了matplotlib。绘制了数据点和集群中心,但图例不是showing.It,只是返回空。
有人能告诉我为什么会发生这种情况吗?
import pandas as pd
df1 = pd.DataFrame(x_trans,columns=['Feature1','Feature2'])
df2 = pd.DataFrame(data = km.labels_,columns=['Breast_Cancer_Type'])
df3 = pd.concat([df1,df2],axis=1)
print(df3)
import matplotlib.pyplot as plt
plt.scatter(df3.iloc[:,0],df3.iloc[:,1],c=km.labels_,cmap='rainbow')
plt.scatter(km.cluster_centers_[:,0],km.cluster_centers_[:,1],color='black')
plt.legend()
plt.show()发布于 2021-06-06 13:05:49
您必须在plt.scatter()函数中添加标签。查看这些examples
https://stackoverflow.com/questions/67855599
复制相似问题