diff --git a/ai_modules/anomaly_detection.py b/ai_modules/anomaly_detection.py new file mode 100644 index 0000000..4b11a6a --- /dev/null +++ b/ai_modules/anomaly_detection.py @@ -0,0 +1,22 @@ +import pandas as pd + +def detect_anomalies(data: pd.Series, z_thresh: float = 3.0): + """ + Simple anomaly detection using Z-score. + Args: + data (pd.Series): Series of water usage values + z_thresh (float): threshold for anomaly detection + Returns: + pd.Series: points detected as anomalies + """ + mean = data.mean() + std = data.std() + z_scores = (data - mean) / std + return data[abs(z_scores) > z_thresh] + +if __name__ == "__main__": + # Example usage with dummy data + readings = pd.Series([100, 105, 98, 500, 102, 97, 103]) + anomalies = detect_anomalies(readings, z_thresh=2.0) + + print("Anomalies detected:\n", anomalies) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cb37f8c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +numpy==2.3.2 +pandas==2.3.2 +python-dateutil==2.9.0.post0 +pytz==2025.2 +six==1.17.0 +tzdata==2025.2