【问题标题】:ValueError: labels_true must be 1D?ValueError:labels_true 必须是 1D?
【发布时间】:2021-02-10 09:16:33
【问题描述】:

如何计算此算法的性能。我试过这个简单的例子: `

 af = AffinityPropagation().fit(X)
 cluster_centers_indices = af.cluster_centers_indices_
 labels = af.labels_
 n_clusters_ = len(cluster_centers_indices)
 print("Homogeneity: %0.3f" % homogeneity_score(X, labels))
 print("Completeness: %0.3f" % metrics.completeness_score(X, labels))`

但我收到以下错误:ValueError: labels_true must be 1D: shape is (56, 52) 请帮忙!

【问题讨论】:

  • 你有一个名为“labels_true”的变量吗?
  • 不,我没有§

标签: python


【解决方案1】:

错误是由于homogeneity_score的使用不正确造成的。

这些指标假定地面实况标签可用于您的输入数据。

在您的代码中,您已将输入数据X 和名为labels 的预测标签提供给homoegeneity_score 函数。正确的用法是:

homogeneity_score(labels_true, labels_pred)

在您的情况下,labels_pred 将是 labels 变量。 labels_true 应该是您应该能够使用该指标的基本事实标签。

completeness_score也是如此。

请参阅此处有关这两个指标的官方文档:

https://scikit-learn.org/stable/modules/generated/sklearn.metrics.homogeneity_score.html https://scikit-learn.org/stable/modules/generated/sklearn.metrics.completeness_score.html

另外,请参阅此答案以更好地了解聚类算法的评估:Performance Analysis of Clustering Algorithms

【讨论】:

  • 在我的情况下,我不能使用'homogenity_score'??
  • 如果你有真实标签来比较你的预测,那么你可以。
猜你喜欢
  • 2018-06-23
  • 1970-01-01
  • 1970-01-01
  • 2016-05-07
  • 2019-03-21
  • 2011-03-13
  • 2019-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多