Difference Scorer

This scorer simply computes the elementwise difference between two series. If the two series are multivariate, it returns a multivariate series.

class darts.ad.scorers.difference_scorer.DifferenceScorer[source]

Bases: AnomalyScorer

Difference Scorer

Attributes

is_probabilistic

Whether the scorer expects a probabilistic prediction as the first input.

is_trainable

Whether the scorer is trainable.

is_univariate

Whether the Scorer is a univariate scorer.

Methods

eval_metric_from_prediction(anomalies, ...)

Computes the anomaly score between series and pred_series, and returns the score of an agnostic threshold metric.

score_from_prediction(series, pred_series)

Computes the anomaly score on the two (sequence of) series.

show_anomalies_from_prediction(series, ...)

Plot the results of the scorer.

eval_metric_from_prediction(anomalies, series, pred_series, metric='AUC_ROC')

Computes the anomaly score between series and pred_series, and returns the score of an agnostic threshold metric.

Parameters
  • anomalies (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) ground truth binary anomaly series (1 if it is an anomaly and 0 if not).

  • series (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) actual series.

  • pred_series (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) predicted series.

  • metric (Literal[‘AUC_ROC’, ‘AUC_PR’]) – The name of the metric function to use. Must be one of “AUC_ROC” (Area Under the Receiver Operating Characteristic Curve) and “AUC_PR” (Average Precision from scores). Default: “AUC_ROC”.

Return type

Union[float, Sequence[float], Sequence[Sequence[float]]]

Returns

  • float – A single metric value for a single univariate series.

  • Sequence[float] – A sequence of metric values for:

    • a single multivariate series.

    • a sequence of univariate series.

  • Sequence[Sequence[float]] – A sequence of sequences of metric values for a sequence of multivariate series. The outer sequence is over the series, and inner sequence is over the series’ components/columns.

property is_probabilistic: bool

Whether the scorer expects a probabilistic prediction as the first input.

Return type

bool

property is_trainable: bool

Whether the scorer is trainable.

Return type

bool

property is_univariate: bool

Whether the Scorer is a univariate scorer.

Return type

bool

score_from_prediction(series, pred_series)

Computes the anomaly score on the two (sequence of) series.

If a pair of sequences is given, they must contain the same number of series. The scorer will score each pair of series independently and return an anomaly score for each pair.

Parameters
Returns

(Sequence of) anomaly score time series

Return type

Union[TimeSeries, Sequence[TimeSeries]]

show_anomalies_from_prediction(series, pred_series, scorer_name=None, anomalies=None, title=None, metric=None)

Plot the results of the scorer.

Computes the anomaly score on the two series. And plots the results.

The plot will be composed of the following:
  • the series and the pred_series.

  • the anomaly score of the scorer.

  • the actual anomalies, if given.

It is possible to:
  • add a title to the figure with the parameter title

  • give personalized name to the scorer with scorer_name

  • show the results of a metric for the anomaly score (AUC_ROC or AUC_PR), if the actual anomalies is provided.

Parameters
  • series (TimeSeries) – The actual series to visualize anomalies from.

  • pred_series (TimeSeries) – The predicted series of series.

  • anomalies (Optional[TimeSeries, None]) – The ground truth of the anomalies (1 if it is an anomaly and 0 if not)

  • scorer_name (Optional[str, None]) – Name of the scorer.

  • title (Optional[str, None]) – Title of the figure

  • metric (Optional[Literal[‘AUC_ROC’, ‘AUC_PR’], None]) – Optionally, the name of the metric function to use. Must be one of “AUC_ROC” (Area Under the Receiver Operating Characteristic Curve) and “AUC_PR” (Average Precision from scores). Default: “AUC_ROC”.