NLL Laplace Scorer¶
Laplace distribution negative log-likelihood Scorer.
The anomaly score is the negative log likelihood of the actual series values under a Laplace distribution estimated from the stochastic prediction.
- class darts.ad.scorers.nll_laplace_scorer.LaplaceNLLScorer(window=1)[source]¶
Bases:
NLLScorer
NLL Laplace Scorer
- Parameters
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
Whether the scorer expects a probabilistic prediction as the first input.
Whether the scorer is trainable.
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
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(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 figuremetric (
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”.