UCRScore

class dtaianomaly.evaluation.UCRScore(tolerance: int = None)[source]

Compute the UCR-Score to evaluate the predicted anomaly scores [39].

The UCR-score is a binary metric for a time series with a single anomalous event starting at time \(t_s\) until time \(t_e\) of length \(w = t_e - t_s + 1\). Denote \(t^*\) as the time step with the highest anomaly score. We define tolerance \(\xi\) to reduce bias towards shorter anomalies [29]. The UCR Score equals 1 if \(t^*\) is near the anomalous event, and 0 otherwise. Formally:

\[\begin{split}UCR_{\text{score}, \xi} = \begin{cases} 1 & t_s - \max(w, \xi) \leq t^* \leq t_e + \max(w, \xi) \\ 0 & \text{otherwise} \end{cases}\end{split}\]
Parameters:
toleranceint, default=None

The minimum tolerance around the ground truth anomalous event to avoid bias towards short anomalies. If None, no tolerance is included.

Examples

>>> from dtaianomaly.evaluation import UCRScore
>>> y_true = [0, 0, 0, 1, 1, 0, 0, 0]
>>> UCRScore().compute(y_true, [0.3, 0.2, 0.5, 0.8, 1.0, 0.9, 0.3, 0.0])
1
>>> UCRScore().compute(y_true, [0.3, 0.2, 0.5, 0.8, 0.9, 0.9, 0.3, 1.0])
0
compute(y_true: ndarray, y_pred: ndarray, **kwargs) float

Compute the performance score.

Evaluate how closely the given anomaly scores align to the ground truth anomaly scores.

Parameters:
y_truearray-like of shape (n_samples)

Ground-truth labels.

y_predarray-like of shape (n_samples)

Predicted anomaly scores.

**kwargs

Additional arguments used for computing the evaluation metric.

Returns:
float

The alignment score of the given ground truth and prediction, according to this score.

Raises:
ValueError

When inputs are not numeric “array-like”s

ValueError

If shapes of y_true and y_pred are not of identical shape

ValueError

If y_true is non-binary.