Detect fraudulent credit card transactions in an extremely imbalanced dataset where fraud is rare. The key challenge is that accuracy is misleading: a model can achieve ~99.8% accuracy by predicting “not fraud” for every transaction while detecting zero fraud cases.
- Build a robust baseline fraud detection pipeline
- Evaluate models with metrics suitable for class imbalance (Precision, Recall, F1, PR-AUC)
- Perform decision threshold tuning based on business constraints (high recall vs. alert quality vs. cost minimization)
- Provide error analysis and a business-ready executive summary
This repository is structured like a real analytics / ML project:
src/contains reusable Python modules (metrics, thresholding, evaluation)notebooks/contain narrative analysis (data understanding → modeling → business impact)reports/contains an executive summary for non-technical stakeholders
Classic Kaggle credit card fraud dataset:
- Features:
V1..V28,Time,Amount - Target:
Class(1 = fraud, 0 = normal)
Note: The dataset is not committed to GitHub.
Placecreditcard.csvindata/raw/.
- data/ raw and processed data (ignored by git)
- notebooks/ narrative analysis notebooks
- src/ reusable Python modules (project core)
- reports/ executive summary and figures
-
Data quality & imbalance analysis
- Class ratio, missing values, feature distributions
- Demonstration of the “accuracy trap” in fraud detection
-
Baseline modeling
- Logistic Regression with class weighting
- Evaluation using Precision, Recall, F1, and PR-AUC
-
Threshold tuning
- Selection of decision thresholds based on:
- minimum precision
- minimum recall
- minimum expected business cost (false negative vs. false positive trade-off)
- Selection of decision thresholds based on:
-
Error analysis
- Detailed inspection of false positives and false negatives
- Translation of model errors into business impact (alert volume, missed fraud loss)
- Precision, Recall, F1-score
- PR-AUC (Average Precision) — preferred under extreme class imbalance
- Confusion Matrix at the selected decision threshold
- Create a virtual environment and install dependencies:
pip install -r requirements.txt-
Place the dataset: data/raw/creditcard.csv
-
Run notebooks in order:
notebooks/01_data_understanding.ipynbnotebooks/02_modeling_thresholding.ipynbnotebooks/03_error_analysis_business.ipynb
- Reusable evaluation and thresholding toolkit in src/
- Three notebooks with a clear analytical narrative
- reports/executive_summary.md with decision-ready conclusions
- Why accuracy fails in fraud detection
- Why PR-AUC and precision/recall are more informative
- How the decision threshold was selected using business cost trade-offs
- What patterns were observed in false positives / false negatives
- What would be done next (stronger models, calibration, monitoring)