📊 Data & Analysisadvancedanomaly-detectionpythonmonitoringdata-engineering

Write an Anomaly Detection Script

Build a script to detect unusual patterns in time-series or tabular data using statistical methods.

The Prompt

prompt.txt
Write an anomaly detection script for the following use case. Include:
1. Method selection: Z-score / IQR / Isolation Forest / DBSCAN — with justification
2. Data preprocessing: how to handle seasonality and trend before anomaly detection
3. Implementation code
4. Threshold setting: how to tune sensitivity
5. Alert mechanism: what to do when an anomaly is detected
6. Visualization code to show anomalies in context

Language: [PYTHON / SQL]
Use case: [DESCRIBE — e.g., Detect sudden spikes or drops in daily API call volume that might indicate an issue with a customer's integration or a potential abuse scenario]
Data description: [WHAT COLUMNS, WHAT SCALE, WHAT'S NORMAL VARIANCE]
Response requirement: [REAL-TIME / DAILY BATCH]

Example Output

Implemented Z-score based anomaly detection for daily API call time series with a 7-day rolling mean/std to handle weekly seasonality. Score threshold of 2.5 flags ~5% of days. Added a Slack webhook alert that fires when 3+ consecutive anomalies are detected. Visualization using matplotlib with anomalies highlighted in red.

FAQ

Which AI model is best for Write an Anomaly Detection Script?

Claude Sonnet 4 — good at statistical method selection and implementation.

How do I use the Write an Anomaly Detection Script prompt?

Copy the prompt, replace the [BRACKETED] placeholders with your specific information, and paste into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.). Implemented Z-score based anomaly detection for daily API call time series with a 7-day rolling mean/std to handle weekly seasonality. Score threshold of 2.5 flags ~5% of days. Added a Slack webhook alert that fires when 3+ consecutive anomalies are detected. Visualization using matplotlib with anomalies highlighted in red.