Evaluation module

This module contains functionality to evaluate performance of an anomaly detector. It can be imported as follows:

>>> from dtaianomaly import evaluation

Custom evaluation metrics can be implemented by extending BinaryMetric or ProbaMetric. The former expects predicted “decisions” (anomaly or not), the latter predicted “scores” (more or less anomalous). This distinction is important for later use in a Worfklow.

Implemented evaluation metrics

Base classes

class dtaianomaly.evaluation.BinaryMetric[source]

A metric that takes as input binary anomaly labels.

compute(y_true: ndarray, y_pred: ndarray, **kwargs) float[source]

Computes the performance score.

Parameters:
  • y_true (array-like of shape (n_samples)) – Ground-truth labels.

  • y_pred (array-like of shape (n_samples)) – Predicted anomaly scores.

Returns:

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

Return type:

float

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.

  • ValueError – If y_pred is non-binary.

class dtaianomaly.evaluation.ProbaMetric[source]

A metric that takes as input continuous anomaly scores.

compute(y_true: ndarray, y_pred: ndarray, **kwargs) float

Computes the performance score.

Parameters:
  • y_true (array-like of shape (n_samples)) – Ground-truth labels.

  • y_pred (array-like of shape (n_samples)) – Predicted anomaly scores.

Returns:

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

Return type:

float

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.