Skip to content

Commit

Permalink
Code refactor for SAD implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanganhngo610 committed Oct 31, 2023
1 parent 3e490cb commit 79c4459
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions river/anomaly/sad.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StandardAbsoluteDeviation(anomaly.base.AnomalyDetector):
Parameters
----------
subtracted_statistic
sub_stat
The statistic to be substracted, then divided by the standard deviation for scoring.
This parameter must be either "mean" or "median".
kwargs
Expand All @@ -44,7 +44,7 @@ class StandardAbsoluteDeviation(anomaly.base.AnomalyDetector):
>>> X = np.random.randn(150, 1)
>>> model = anomaly.StandardAbsoluteDeviation(subtracted_statistic="mean", ddof=1)
>>> model = anomaly.StandardAbsoluteDeviation(sub_stat="mean", ddof=1)
>>> for x, _ in stream.iter_array(X):
... model.learn_one(x)
Expand All @@ -60,17 +60,17 @@ class StandardAbsoluteDeviation(anomaly.base.AnomalyDetector):
"""

def __init__(self, subtracted_statistic="mean", **kwargs):
def __init__(self, sub_stat="mean", **kwargs):
super().__init__()
self.variance = stats.Var(**kwargs)

if subtracted_statistic == "mean":
if sub_stat == "mean":
self.subtracted_statistic = stats.Mean()
elif subtracted_statistic == "median":
elif sub_stat == "median":
self.subtracted_statistic = stats.Quantile(q=0.5)
else:
raise ValueError(
f"Unknown subtracted statistic {subtracted_statistic}, expected one of median, mean."
f"Unknown subtracted statistic {sub_stat}, expected one of median, mean."
)

def learn_one(self, x):
Expand Down

0 comments on commit 79c4459

Please sign in to comment.