GaussianScorer¶
Univariate Gaussian anomaly detector.
This is a supervised anomaly detector. It fits a Gaussian distribution to the target values. The anomaly score is then computed as so:
This makes it so that the anomaly score is between 0 and 1.
Parameters¶
-
window_size
Default →
None
Set this to fit the Gaussian distribution over a window of recent values.
-
grace_period
Default →
100
Number of samples before which a 0 is always returned. This is handy because the Gaussian distribution needs time to stabilize, and will likely produce overly high anomaly score for the first samples.
Examples¶
import random
from river import anomaly
rng = random.Random(42)
detector = anomaly.GaussianScorer()
for y in (rng.gauss(0, 1) for _ in range(100)):
detector = detector.learn_one(None, y)
detector.score_one(None, -3)
0.999477...
detector.score_one(None, 3)
0.999153...
detector.score_one(None, 0)
0.052665...
detector.score_one(None, 0.5)
0.383717...
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