Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ai_modules/anomaly_detection.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The anomaly detection function is clear and well-documented. A few suggestions:

  1. Consider adding a check for std == 0 to avoid division by zero errors.
  2. In the example usage, it might help to explain why z_thresh=2.0 is chosen (e.g., more sensitive to outliers).
  3. Optionally, you could mention that this method assumes a roughly normal distribution for data.

Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions requirements.txt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requirements.txt is clear and version-pinned, which is great for reproducibility. A few suggestions:

  1. Double-check if numpy==2.3.2 and pandas==2.3.2 are compatible; sometimes older versions of one library may conflict with the other.
  2. Consider whether all dependencies (like six or tzdata) are actually used in the project — removing unused packages can simplify the environment.
  3. Optionally, you could mention Python version compatibility, e.g., if this works for Python 3.11 or higher.

Original file line number Diff line number Diff line change
@@ -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