src.evaluation_metric.clustering_purity

src.evaluation_metric.clustering_purity(pred_clusters: torch.Tensor, gt_classes: torch.Tensor) torch.Tensor[source]

Clustering purity for clusters.

\(n\) is the number of instances, \(\mathcal{C}_i\) represent the predicted class \(i\) and \(\mathcal{C}^{gt}_j\) is ground truth class \(j\):

\[\text{clustering purity} = \frac{1}{n} \sum_{i=1}^{k} \max_{j\in\{1,...,k\}} |\mathcal{C}_i \cap \mathcal{C}^{gt}_{j}|\]
Parameters
  • pred_clusters

    \((b\times n)\) predicted clusters. \(n\): number of instances.

    e.g. [[0,0,1,2,1,2]
          [0,1,2,2,1,0]]
    

  • gt_classes

    \((b\times n)\) ground truth classes

    e.g. [['car','car','bike','bike','person','person'],
          ['bus','bus','cat', 'sofa',  'cat',  'sofa' ]]
    

Returns

\((b)\) clustering purity