Evaluation

The tsseg.metrics namespace provides classes implementing common segmentation quality measures. Every metric inherits from tsseg.metrics.BaseMetric and shares the same compute(y_true, y_pred) contract (with an update / compute variant for streaming use).

Change-point metrics

These metrics compare two sets of sparse change-point indices.

tsseg.metrics.F1Score

Computes the F1-score for change point detection.

tsseg.metrics.Covering

Computes the Covering score for a segmentation.

tsseg.metrics.HausdorffDistance

Computes the Hausdorff distance between two sets of change points.

tsseg.metrics.GaussianF1Score

Gaussian-weighted alternative to the classic F1 score.

tsseg.metrics.BidirectionalCovering

Bidirectional extension of the classical Covering metric.

State-labelling metrics

These metrics compare two dense label arrays of equal length, aligning predicted to ground-truth states when needed (e.g. Hungarian matching).

tsseg.metrics.AdjustedRandIndex

Computes the Adjusted Rand Index (ARI).

tsseg.metrics.AdjustedMutualInformation

Computes the Adjusted Mutual Information (AMI).

tsseg.metrics.NormalizedMutualInformation

Computes the Normalized Mutual Information (NMI).

tsseg.metrics.WeightedAdjustedRandIndex

Computes the Weighted Adjusted Rand Index (WARI).

tsseg.metrics.WeightedNormalizedMutualInformation

Computes the Weighted Normalized Mutual Information (WNMI).

tsseg.metrics.StateMatchingScore

Computes the State Matching Score (SMS).

Base protocol

class tsseg.metrics.BaseMetric(**kwargs)[source]

Bases: ABC

Base class for all metrics.

abstractmethod compute(y_true, y_pred, **kwargs)[source]

Computes the value of the metric.

Parameters:
  • y_true (ndarray) – Ground truth labels or change points.

  • y_pred (ndarray) – Predicted labels or change points.

  • **kwargs – Additional arguments for metric computation.

Return type:

dict[str, float]

Returns:

A dictionary containing metric names and their values.

Usage

from tsseg.metrics import F1Score, StateMatchingScore

# Change-point evaluation
f1 = F1Score(margin=5)
result = f1.compute(y_true_cps, y_pred_cps)
print(result["f1"])

# State-labelling evaluation
sms = StateMatchingScore()
result = sms.compute(y_true_labels, y_pred_labels)
print(result["score"])

See Getting started for end-to-end examples that combine detectors and metrics.