Norm Scorer¶
Norm anomaly score (of given order) [1].
References
- class darts.ad.scorers.norm_scorer.NormScorer(ord=None, component_wise=False)[source]¶
Bases:
darts.ad.scorers.scorers.NonFittableAnomalyScorer
Returns the elementwise norm of a given order between two series’ values.
If component_wise is False, the norm is computed between vectors made of the series’ components (one norm per timestamp).
If component_wise is True, for any ord this effectively amounts to computing the absolute value of the difference.
The scoring function expects two series.
If the two series are multivariate of width w:
if component_wise is set to False: it returns a univariate series (width=1).
if component_wise is set to True: it returns a multivariate series of width w.
If the two series are univariate, it returns a univariate series regardless of the parameter component_wise.
- Parameters
ord – Order of the norm. Options are listed under ‘Notes’ at: <https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html>. Default: None
component_wise (
bool
) – Whether to compare components of the two series in isolation (True), or jointly (False). Default: False
Attributes
Whether the scorer expects a probabilistic prediction for its first input.
Methods
eval_accuracy_from_prediction
(...[, metric])Computes the anomaly score between actual_series and pred_series, and returns the score of an agnostic threshold metric.
score_from_prediction
(actual_series, pred_series)Computes the anomaly score on the two (sequence of) series.
show_anomalies_from_prediction
(...[, ...])Plot the results of the scorer.
- eval_accuracy_from_prediction(actual_anomalies, actual_series, pred_series, metric='AUC_ROC')¶
Computes the anomaly score between actual_series and pred_series, and returns the score of an agnostic threshold metric.
- Parameters
actual_anomalies (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – The (sequence of) ground truth of the anomalies (1 if it is an anomaly and 0 if not)actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – The (sequence of) actual series.pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – The (sequence of) predicted series.metric (
str
) – Optionally, metric function to use. Must be one of “AUC_ROC” and “AUC_PR”. Default: “AUC_ROC”
- Returns
- Score of an agnostic threshold metric for the computed anomaly score
float
if actual_series and actual_series are univariate series (dimension=1).Sequence[float]
if actual_series and actual_series are multivariate series (dimension>1),
returns one value per dimension, or * if actual_series and actual_series are sequences of univariate series, returns one value per series
Sequence[Sequence[float]]]
if actual_series and actual_series are sequences
of multivariate series. Outer Sequence is over the sequence input and the inner Sequence is over the dimensions of each element in the sequence input.
- Return type
Union[float, Sequence[float], Sequence[Sequence[float]]]
- property is_probabilistic: bool¶
Whether the scorer expects a probabilistic prediction for its first input.
- Return type
bool
- score_from_prediction(actual_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
actual_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – The (sequence of) actual series.pred_series (
Union
[TimeSeries
,Sequence
[TimeSeries
]]) – The (sequence of) predicted series.
- Returns
(Sequence of) anomaly score time series
- Return type
Union[TimeSeries, Sequence[TimeSeries]]
- show_anomalies_from_prediction(actual_series, pred_series, scorer_name=None, actual_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 actual_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
actual_series (
TimeSeries
) – The actual series to visualize anomalies from.pred_series (
TimeSeries
) – The predicted series of actual_series.actual_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 figuremetric (
Optional
[str
]) – Optionally, Scoring function to use. Must be one of “AUC_ROC” and “AUC_PR”. Default: “AUC_ROC”