pyagc.metrics.label_metrics

label_metrics(y_true: Union[Tensor, ndarray], y_pred: Union[Tensor, ndarray], metrics: Union[str, Tuple[str, ...]] = ('NMI', 'ARI', 'ACC', 'F1')) Dict[str, float][source]

Compute clustering evaluation metrics.

If accuracy or Macro-F1 score is requested, it performs alignment of predicted clusters with true labels using the Hungarian algorithm to account for label mismatches.

Parameters:
  • y_true (torch.Tensor or np.ndarray) – True labels of shape (n_samples,).

  • y_pred (torch.Tensor or np.ndarray) – Predicted cluster labels of shape (n_samples,).

  • metrics (str or tuple of str, optional) – The metrics to compute. Can be one or more of ('NMI', 'ARI', 'Homo', 'Comp', 'ACC', 'F1'). Default is ('NMI', 'ARI', 'ACC', 'F1').

Returns:

Dict[str, float] – Dictionary mapping metric names to their computed values.

Example

>>> result = label_metrics(y_true, y_pred, metrics=('NMI', 'ARI', 'ACC'))
>>> print(result)
{'NMI': 0.85, 'ARI': 0.72, 'ACC': 0.89}