Detecting unusual spending behavior in business transaction data using feature engineering and unsupervised anomaly detection.
Problem: Given transaction data for businesses, can we identify unusual spending patterns that may indicate fraud, accounting errors, or behavior shifts?
This project explores that question through a realistic exploratory prototype — not a production system. The emphasis is on feature engineering and interpretability, not model complexity.
Open transaction_analysis.ipynb to see the full analysis:
- Synthetic dataset generation (6,400 transactions, 5 businesses, 12 months)
- Exploratory analysis
- Feature engineering — 10 contextual features
- Three anomaly detection methods compared
- Visualizations and results
- Honest limitations and next steps
- SQL implementation — core anomaly logic in SQLite
Raw transaction amounts are poor anomaly signals. A $10,000 payment is routine for one business and alarming for another. The interesting work is building context-aware features:
| Feature | What it captures |
|---|---|
amount_zscore_biz |
Unusual for this account's history? |
amount_zscore_vendor |
Unusual for this vendor relationship? |
is_new_vendor |
First-ever payment to this payee? |
rolling_7d_count |
Transaction frequency spike this week? |
is_near_duplicate |
Same amount + same vendor within 48 hrs? |
| Method | Description |
|---|---|
| Rule-based scoring | Human-readable thresholds, fully auditable |
| Z-score composite | Statistical baseline, SQL-friendly |
| Isolation Forest | Tree-based unsupervised ML |
| SQL queries | Core anomaly logic in SQLite — production-ready |
Python · pandas · NumPy · scikit-learn · matplotlib · SQLite
A portfolio project exploring anomaly detection in a fintech/business banking context.