Level 2 / Project 14 - Anomaly Flagger¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Estimated time: 45 minutes
Focus¶
- threshold and outlier tagging
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-2/14-anomaly-flagger
python project.py data/sample_input.txt
python project.py data/sample_input.txt --z-threshold 3.0
python project.py data/sample_input.txt --iqr-factor 3.0
pytest -q
Expected terminal output¶
Expected artifacts¶
- Anomaly report on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
--methodflag to use only z-score or only IQR detection. - Add a visual indicator (e.g. asterisks) showing where anomalies fall.
- Output the "cleaned" dataset with anomalies removed.
Break it (required) — Core¶
- Feed a dataset with all identical values — does z-score divide by zero?
- Feed a dataset with fewer than 4 values — does IQR work?
- Feed a dataset with only 1 value — what stats are meaningful?
Fix it (required) — Core¶
- Guard against zero std_dev in z_score calculation.
- Return empty anomalies list when dataset is too small for IQR.
- Handle single-value datasets gracefully in statistics.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- What is a z-score and what does |z| > 2 mean practically?
- How does the IQR method differ from z-score for skewed data?
- Why might the same value be flagged by one method but not the other?
- Where is anomaly detection used in real systems (monitoring, fraud, QA)?
Mastery check¶
You can move on when you can: - calculate mean and standard deviation by hand for a small dataset, - explain when z-score fails (non-normal distributions), - describe why IQR is more robust to outliers than mean-based methods, - implement percentile calculation from scratch.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|