StandardAbsoluteDeviation¶
Standard Absolute Deviation (SAD).
SAD is the model that calculates the anomaly score by using the deviation from the mean/median, divided by the standard deviation of all the points seen within the data stream. The idea of this model is based on the \(3 \times \sigma\) rule described in 1.
This implementation is adapted from the implementation within PySAD (Python Streaming Anomaly Detection) 2.
As a univariate anomaly detection algorithm, this implementation is adapted to River
in a similar way as that of the GaussianScorer
algorithm, with the variable taken into the account at the learning phase and scoring phase under variable y
, ignoring x
.
Parameters¶
-
sub_stat
Type → stats.base.Univariate
Default →
None
The statistic to be subtracted, then divided by the standard deviation for scoring. Defaults to
stats.Mean
()`.
Examples¶
import random
from river import anomaly
from river import stats
from river import stream
rng = random.Random(42)
model = anomaly.StandardAbsoluteDeviation(sub_stat=stats.Mean())
for _ in range(150):
y = rng.gauss(0, 1)
model = model.learn_one(None, y)
model.score_one(None, 2)
2.057...
model.score_one(None, 0)
0.084...
model.score_one(None, 1)
0.986...
Methods¶
learn_one
Update the model.
Parameters
- x — 'dict'
- y — 'base.typing.Target'
Returns
SupervisedAnomalyDetector: self
score_one
Return an outlier score.
A high score is indicative of an anomaly. A low score corresponds a normal observation.
Parameters
- x — 'dict'
- y — 'base.typing.Target'
Returns
float: An anomaly score. A high score is indicative of an anomaly. A low score corresponds a