Skip to content

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×σ 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

    Typestats.base.Univariate | None

    DefaultNone

    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.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'

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


  1. Hochenbaum, J., Vallis, O.S., Kejariwal, A., 2017. Automatic Anomaly Detection in the Cloud Via Statistical Learning. https://doi.org/10.48550/ARXIV.1704.07706. 

  2. Yilmaz, S.F., Kozat, S.S., 2020. PySAD: A Streaming Anomaly Detection Framework in Python. https://doi.org/10.48550/ARXIV.2009.02572.