Scorers Base Classes

class darts.ad.scorers.scorers.AnomalyScorer(is_univariate, window)[source]

Bases: ABC

Base class for all anomaly scorers

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.

Parameters
  • is_univariate (bool) – Whether the scorer is a univariate scorer.

  • window (int) – Integer value indicating the size of the window W used by the scorer to transform the series into an anomaly score. A scorer will slice the given series into subsequences of size W and returns a value indicating how anomalous these subset of W values are. A post-processing step will convert this anomaly score into a point-wise anomaly score (see definition of window_transform). The window size should be commensurate to the expected durations of the anomalies one is looking for.

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')[source]

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)[source]

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)[source]

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]) – The ground truth of the anomalies (1 if it is an anomaly and 0 if not)

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

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

  • metric (Optional[Literal[‘AUC_ROC’, ‘AUC_PR’]]) – 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”.

class darts.ad.scorers.scorers.FittableAnomalyScorer(is_univariate, window, window_agg, diff_fn=<function ae>, n_jobs=1)[source]

Bases: AnomalyScorer

Base class of scorers that require training.

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(anomalies, series[, metric])

Computes the anomaly score of the given time series, and returns the score of an agnostic threshold metric.

eval_metric_from_prediction(anomalies, ...)

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

fit(series)

Fits the scorer on the given time series.

fit_from_prediction(series, pred_series)

Fits the scorer on the two (sequences of) series.

score(series)

Computes the anomaly score on the given series.

score_from_prediction(series, pred_series)

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

show_anomalies(series[, anomalies, ...])

Plot the results of the scorer.

show_anomalies_from_prediction(series, ...)

Plot the results of the scorer.

Parameters
  • is_univariate (bool) – Whether the scorer is a univariate scorer.

  • window (int) – Integer value indicating the size of the window W used by the scorer to transform the series into an anomaly score. A scorer will slice the given series into subsequences of size W and returns a value indicating how anomalous these subset of W values are. A post-processing step will convert this anomaly score into a point-wise anomaly score (see definition of window_transform). The window size should be commensurate to the expected durations of the anomalies one is looking for.

  • window_agg (bool) – Whether to transform/aggregate window-wise anomaly scores into a point-wise anomaly scores.

  • diff_fn (Callable[…, Union[float, List[float], ndarray, List[ndarray]]]) – The differencing function to use to transform the predicted and actual series into one series. The scorer is then applied to this series. Must be one of Darts per-time-step metrics (e.g., ae() for the absolute difference, err() for the difference, se() for the squared difference, …). By default, uses the absolute difference (ae()).

  • n_jobs (int) – The number of jobs to run in parallel. Parallel jobs are created only when a Sequence[TimeSeries] is passed as input, parallelising operations regarding different TimeSeries. Defaults to 1 (sequential). Setting the parameter to -1 means using all the available processors.

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(anomalies, series[, metric])

Computes the anomaly score of the given time series, and returns the score of an agnostic threshold metric.

eval_metric_from_prediction(anomalies, ...)

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

fit(series)

Fits the scorer on the given time series.

fit_from_prediction(series, pred_series)

Fits the scorer on the two (sequences of) series.

score(series)

Computes the anomaly score on the given series.

score_from_prediction(series, pred_series)

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

show_anomalies(series[, anomalies, ...])

Plot the results of the scorer.

show_anomalies_from_prediction(series, ...)

Plot the results of the scorer.

eval_metric(anomalies, series, metric='AUC_ROC')[source]

Computes the anomaly score of the given time 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) series to detect anomalies from.

  • 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 score/metric for univariate series series (with only one component/column).

  • Sequence[float] – A sequence (list) of scores for:

    • multivariate series series (multiple components). Gives a score for each component.

    • a sequence (list) of univariate series series. Gives a score for each series.

  • Sequence[Sequence[float]] – A sequence of sequences of scores for a sequence of multivariate series series. Gives a score for each series (outer sequence) and component (inner sequence).

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.

fit(series)[source]

Fits the scorer on the given time series.

If a sequence of series, the scorer is fitted on the concatenation of the sequence.

The assumption is that series is generally anomaly-free.

Parameters

series (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) series with no anomalies.

Returns

Fitted Scorer.

Return type

self

fit_from_prediction(series, pred_series)[source]

Fits the scorer on the two (sequences of) series.

The function diff_fn passed as a parameter to the scorer, will transform pred_series and series into one series. By default, diff_fn will compute the absolute difference (Default: ae()). If pred_series and series are sequences, diff_fn will be applied to all pairwise elements of the sequences.

The scorer will then be fitted on this (sequence of) series. If a sequence of series is given, the scorer will be fitted on the concatenation of the sequence.

The scorer assumes that the (sequence of) series is anomaly-free.

If any of the series is stochastic (with n_samples>1), diff_fn is computed on quantile 0.5.

Parameters
Returns

Fitted Scorer.

Return type

self

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(series)[source]

Computes the anomaly score on the given series.

If a sequence of series is given, the scorer will score each series independently and return an anomaly score for each series in the sequence.

Parameters

series (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) series to detect anomalies from.

Returns

(Sequence of) anomaly score time series

Return type

Union[TimeSeries, Sequence[TimeSeries]]

score_from_prediction(series, pred_series)[source]

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

The function diff_fn passed as a parameter to the scorer, will transform pred_series and series into one “difference” series. By default, diff_fn will compute the absolute difference (Default: ae()). If series and pred_series are sequences, diff_fn will be applied to all pairwise elements of the sequences.

The scorer will then transform this series into an anomaly score. If a sequence of series is given, the scorer will score each series independently and return an anomaly score for each series in the sequence.

Parameters
Returns

(Sequence of) anomaly score time series

Return type

Union[TimeSeries, Sequence[TimeSeries]]

show_anomalies(series, anomalies=None, scorer_name=None, title=None, metric=None)[source]

Plot the results of the scorer.

Computes the score on the given series input. And plots the results.

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

  • the anomaly score of the score.

  • 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 series to visualize anomalies from.

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

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

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

  • metric (Optional[Literal[‘AUC_ROC’, ‘AUC_PR’]]) – 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”.

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]) – The ground truth of the anomalies (1 if it is an anomaly and 0 if not)

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

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

  • metric (Optional[Literal[‘AUC_ROC’, ‘AUC_PR’]]) – 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”.

class darts.ad.scorers.scorers.NLLScorer(window)[source]

Bases: AnomalyScorer

Parent class for all LikelihoodScorer

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.

Parameters

window – Integer value indicating the size of the window W used by the scorer to transform the series into an anomaly score. A scorer will slice the given series into subsequences of size W and returns a value indicating how anomalous these subset of W values are. A post-processing step will convert this anomaly score into a point-wise anomaly score (see definition of window_transform). The window size should be commensurate to the expected durations of the anomalies one is looking for.

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]) – The ground truth of the anomalies (1 if it is an anomaly and 0 if not)

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

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

  • metric (Optional[Literal[‘AUC_ROC’, ‘AUC_PR’]]) – 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”.

class darts.ad.scorers.scorers.WindowedAnomalyScorer(is_univariate, window, window_agg, diff_fn)[source]

Bases: FittableAnomalyScorer

Base class for anomaly scorers that rely on windows to detect anomalies

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(anomalies, series[, metric])

Computes the anomaly score of the given time series, and returns the score of an agnostic threshold metric.

eval_metric_from_prediction(anomalies, ...)

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

fit(series)

Fits the scorer on the given time series.

fit_from_prediction(series, pred_series)

Fits the scorer on the two (sequences of) series.

score(series)

Computes the anomaly score on the given series.

score_from_prediction(series, pred_series)

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

show_anomalies(series[, anomalies, ...])

Plot the results of the scorer.

show_anomalies_from_prediction(series, ...)

Plot the results of the scorer.

Parameters
  • is_univariate (bool) – Whether the scorer is a univariate scorer. If True and when using multivariate series, the scores are computed on the concatenated components/columns in the considered window to compute one score.

  • window (int) – Integer value indicating the size of the window W used by the scorer to transform the series into an anomaly score. A scorer slices the given series into subsequences of size W and returns a value indicating how anomalous these subsets of W values are. A post-processing step will convert the anomaly scores into point-wise anomaly scores (see definition of window_transform). The window size should be commensurate to the expected durations of the anomalies one is looking for.

  • window_agg (bool) – Whether to transform/aggregate window-wise anomaly scores into point-wise anomaly scores.

  • diff_fn (Callable[…, Union[float, List[float], ndarray, List[ndarray]]]) – The differencing function to use to transform the predicted and actual series into one series. The scorer is then applied to this series. Must be one of Darts per-time-step metrics (e.g., ae() for the absolute difference, err() for the difference, se() for the squared difference, …). By default, uses the absolute difference (ae()).

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(anomalies, series[, metric])

Computes the anomaly score of the given time series, and returns the score of an agnostic threshold metric.

eval_metric_from_prediction(anomalies, ...)

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

fit(series)

Fits the scorer on the given time series.

fit_from_prediction(series, pred_series)

Fits the scorer on the two (sequences of) series.

score(series)

Computes the anomaly score on the given series.

score_from_prediction(series, pred_series)

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

show_anomalies(series[, anomalies, ...])

Plot the results of the scorer.

show_anomalies_from_prediction(series, ...)

Plot the results of the scorer.

eval_metric(anomalies, series, metric='AUC_ROC')

Computes the anomaly score of the given time 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) series to detect anomalies from.

  • 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 score/metric for univariate series series (with only one component/column).

  • Sequence[float] – A sequence (list) of scores for:

    • multivariate series series (multiple components). Gives a score for each component.

    • a sequence (list) of univariate series series. Gives a score for each series.

  • Sequence[Sequence[float]] – A sequence of sequences of scores for a sequence of multivariate series series. Gives a score for each series (outer sequence) and component (inner sequence).

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.

fit(series)

Fits the scorer on the given time series.

If a sequence of series, the scorer is fitted on the concatenation of the sequence.

The assumption is that series is generally anomaly-free.

Parameters

series (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) series with no anomalies.

Returns

Fitted Scorer.

Return type

self

fit_from_prediction(series, pred_series)

Fits the scorer on the two (sequences of) series.

The function diff_fn passed as a parameter to the scorer, will transform pred_series and series into one series. By default, diff_fn will compute the absolute difference (Default: ae()). If pred_series and series are sequences, diff_fn will be applied to all pairwise elements of the sequences.

The scorer will then be fitted on this (sequence of) series. If a sequence of series is given, the scorer will be fitted on the concatenation of the sequence.

The scorer assumes that the (sequence of) series is anomaly-free.

If any of the series is stochastic (with n_samples>1), diff_fn is computed on quantile 0.5.

Parameters
Returns

Fitted Scorer.

Return type

self

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(series)

Computes the anomaly score on the given series.

If a sequence of series is given, the scorer will score each series independently and return an anomaly score for each series in the sequence.

Parameters

series (Union[TimeSeries, Sequence[TimeSeries]]) – The (sequence of) series to detect anomalies from.

Returns

(Sequence of) anomaly score time series

Return type

Union[TimeSeries, Sequence[TimeSeries]]

score_from_prediction(series, pred_series)

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

The function diff_fn passed as a parameter to the scorer, will transform pred_series and series into one “difference” series. By default, diff_fn will compute the absolute difference (Default: ae()). If series and pred_series are sequences, diff_fn will be applied to all pairwise elements of the sequences.

The scorer will then transform this series into an anomaly score. If a sequence of series is given, the scorer will score each series independently and return an anomaly score for each series in the sequence.

Parameters
Returns

(Sequence of) anomaly score time series

Return type

Union[TimeSeries, Sequence[TimeSeries]]

show_anomalies(series, anomalies=None, scorer_name=None, title=None, metric=None)

Plot the results of the scorer.

Computes the score on the given series input. And plots the results.

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

  • the anomaly score of the score.

  • 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 series to visualize anomalies from.

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

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

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

  • metric (Optional[Literal[‘AUC_ROC’, ‘AUC_PR’]]) – 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”.

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]) – The ground truth of the anomalies (1 if it is an anomaly and 0 if not)

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

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

  • metric (Optional[Literal[‘AUC_ROC’, ‘AUC_PR’]]) – 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”.