spine.utils.metrics

Various metrics used to evaluate clustering.

Functions

ami(truth, pred[, batch_ids])

Computes the Adjusted Mutual Information (AMI) between two sets of labels.

ari(truth, pred[, batch_ids])

Computes the Adjusted Rand Index (ARI) between two sets of labels.

bd(truth, truth_unique, truth_counts, pred, ...)

Computes the Best Dice (BD) between two sets of labels.

eff(truth, pred[, batch_ids, per_cluster])

Assignment efficiency, evaluated per true cluster and averaged.

pur(truth, pred[, batch_ids, per_cluster])

Assignment purity.

pur_eff(truth, pred[, batch_ids, per_cluster])

Assignment purity and efficiency.

sbd(truth, pred[, batch_ids])

Compute the Symmetric Best Dice (SBD) score between two sets of labels.

unique_labels(labels[, batch_ids])

Transforms labels to range from 0 to C-1 labels (with C the number of unique values in the label array.

spine.utils.metrics.pur(truth, pred, batch_ids=None, per_cluster=True)[source]

Assignment purity.

Parameters:
  • truth (np.ndarray) –

    1. Set of true labels

  • pred (np.ndarray) –

    1. Set of predicted labels

  • batch_ids (np.ndarray, optional) –

    1. Batch IDs

  • per_cluster (bool, default True) – If True, computes the purity per predicted cluster, than averages it

Returns:

Assignment purity

Return type:

float

spine.utils.metrics.eff(truth, pred, batch_ids=None, per_cluster=True)[source]

Assignment efficiency, evaluated per true cluster and averaged.

Parameters:
  • truth (np.ndarray) –

    1. Set of true labels

  • pred (np.ndarray) –

    1. Set of predicted labels

  • batch_ids (np.ndarray, optional) –

    1. Batch IDs

  • per_cluster (bool, default True) – If True, computes the efficiency per truth cluster, than averages it

Returns:

Assignment efficiency

Return type:

float

spine.utils.metrics.pur_eff(truth, pred, batch_ids=None, per_cluster=True)[source]

Assignment purity and efficiency.

Parameters:
  • truth (np.ndarray) –

    1. Set of true labels

  • pred (np.ndarray) –

    1. Set of predicted labels

  • batch_ids (np.ndarray, optional) –

    1. Batch IDs

  • per_cluster (bool, default True) – If True, computes the metrics per predicted cluster, than averages them

Returns:

  • float – Assignment purity

  • float – Assignment efficiency

spine.utils.metrics.ari(truth, pred, batch_ids=None)[source]

Computes the Adjusted Rand Index (ARI) between two sets of labels.

Parameters:
  • truth (np.ndarray) –

    1. Set of true labels

  • pred (np.ndarray) –

    1. Set of predicted labels

  • batch_ids (np.ndarray, optional) –

    1. Batch IDs

Returns:

Adjusted Rand Index (ARI) value

Return type:

float

spine.utils.metrics.ami(truth, pred, batch_ids=None)[source]

Computes the Adjusted Mutual Information (AMI) between two sets of labels.

Parameters:
  • truth (np.ndarray) –

    1. Set of true labels

  • pred (np.ndarray) –

    1. Set of predicted labels

  • batch_ids (np.ndarray, optional) –

    1. Batch IDs

Returns:

Adjusted Mutual Information (AMI) value

Return type:

float

spine.utils.metrics.sbd(truth, pred, batch_ids=None)[source]

Compute the Symmetric Best Dice (SBD) score between two sets of labels.

Parameters:
  • truth (np.ndarray) –

    1. Set of true labels

  • pred (np.ndarray) –

    1. Set of predicted labels

  • batch_ids (np.ndarray, optional) –

    1. Batch IDs

Returns:

Symmetric best dice value

Return type:

float