1

How can I compute the performance of this algorithm. I tried this simple example : `

 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))`

But i am getting the following error: ValueError: labels_true must be 1D: shape is (56, 52) Please help!

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
ab20225
  • 83
  • 2
  • 11

1 Answers1

2

The error occurs due to the incorrect usage of homogeneity_score.

These metrics assume that the ground truth labels are available for your input data.

In your code, you have supplied the input data X and predicted labels called labels to the homoegeneity_score function. The correct usage would be:

homogeneity_score(labels_true, labels_pred)

where labels_pred in your case would be the labels variable. And labels_true should be the ground truth labels that you should have to be able to use the metric.

The same is the case with completeness_score.

Refer to the official documentation for both these metrics here:

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

Also, refer to this answer for a better understanding on evaluation of clustering algorithms: Performance Analysis of Clustering Algorithms

Ishwar Venugopal
  • 872
  • 6
  • 17