Your question is Metrics Anomaly Detection. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Zoox vehicle telemetry streams contain metrics such as battery temperature, latency, and sensor voltage. Implement a function that identifies anomalous readings using a rolling Hampel filter, without allowing the current reading to influence its own baseline.
For each reading, compare it with the preceding window_size readings, or all preceding readings if fewer are available. Do not evaluate a reading until at least three preceding readings exist. Let m be the window median and MAD be the median of the absolute deviations from m. Define the robust scale as 1.4826 * MAD. A reading is anomalous when its absolute difference from m is greater than threshold * robust_scale. If MAD is zero, any reading different from the median is anomalous.
Return the zero-based indices of anomalous readings in chronological order. The input metric stream is not modified.
metrics, a list of integers or floats; window_size, an odd integer; and positive float threshold.def detect_anomalies(metrics, window_size, threshold):