Rolling z-Score Anomaly Detection

medium
Unit 20 · Anomaly Detection0/1 to milestone

Flag points that are unusual relative to the recent past. Implement rolling_anomalies(x, window, threshold=3.0):

  • for each index t >= window, compute the mean and sample std (ddof=1) of the previous window values x[t-window : t] (not including x[t])
  • flag t if |x[t] - mean| / std > threshold; if std == 0, flag it when x[t] != mean
  • return the list of flagged indices
#anomaly-detection#time-series2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Rolling z-Score Anomaly Detection · TechGradify