0

我有 78 行和 131 列,我需要将 python matplotlib 中每个集群的平均轮廓分数绘制为折线图。我做了这些代码并且工作得很好,但我不知道如何绘图?

mean = KMeans(n_clusters = 2)
kmean.fit(Data1)
centroids = kmean.cluster_centers_
print("Shape of Centroids Array: " + str(centroids.shape))

print()
print(centroids)

from collections import Counter
labels = kmean.labels_
c = Counter(labels)
print(c.most_common())

Record_array =Data1.values
print(Record_array)
mean_sihouette_score = ss(Record_array, labels)
print(mean_sihouette_score)

for cluster_number in range(0,2):

    print("Cluster {} contains {} samples with percentage of {:.2f}%".format(cluster_number, c[cluster_number], c[cluster_number]/sum(c.values()) *100))
4

1 回答 1

1

绘制平均轮廓分数的编码并非易事。我通常把黄砖做好。

在这里,你可以看看。

https://www.scikit-yb.org/en/latest/api/cluster/silhouette.html

或他们的代码在这里(请预先安装yellowbrick)

from yellowbrick.cluster import SilhouetteVisualizer

model = KMeans(5, random_state=42)
visualizer = SilhouetteVisualizer(model, colors='yellowbrick')

visualizer.fit(X)        # Fit the data to the visualizer
visualizer.show()        # Finalize and render the figure
于 2020-06-06T03:38:22.213 回答