Transaction Records
PCA-transformed features plus Time and Amount, split into 227,845 training and 56,962 test transactions.
An end-to-end fraud detection pipeline on the classic credit-card dataset that addresses extreme class imbalance, compares multiple models, explains predictions with SHAP, and selects a threshold using explicit business costs.
Fraud detection is not just a modelling exercise. It is a sequence of practical questions: What does the data look like? Can a model find the rare signal? Why did it raise an alert? And when should an alert actually be raised?
This project walks through that path — from stratified preparation and imbalance-aware modelling to SHAP explanations and cost-sensitive threshold selection.
A prediction score is only useful when its consequences are understood. The real test is finding rare fraud without overwhelming analysts with false alarms.
PCA-transformed features plus Time and Amount, split into 227,845 training and 56,962 test transactions.
Fraud cases represent roughly 0.17 % of the data, so accuracy alone is a misleading success metric.
Preparation → Modelling → SHAP explainability → Cost-sensitive threshold evaluation form a complete analysis path.
Stratified splits, class weighting and SMOTE-style strategies keep the rare fraud examples visible throughout training and evaluation.
Explore, scale, and create a stratified train/test split.
Compare Logistic Regression, RF, XGBoost and LightGBM.
SHAP global importance and local force/waterfall plots.
Choose a threshold using explicit false-positive and false-negative costs.
Class weighting, stratified splits and resampling strategies keep the rare fraud class visible during training.
Precision, recall, F1, PR-AUC and ROC-AUC replace accuracy as the primary evaluation lens.
Global and local explanations sit alongside a cost matrix so the operating threshold reflects real trade-offs.
Metrics describe the saved experiment. They are not a promise of future performance on live traffic.
High fraction of flagged transactions that are truly fraudulent.
Strong ability to surface the rare fraud cases.
Balanced detection quality under severe class imbalance.
Strong ranking ability across the full score spectrum.
Minimum-cost operating point under FN cost 150, FP cost 5, TP cost 10 (recorded test cost 9,160).
PCA-transformed columns limit domain interpretation even though SHAP can still rank their influence.
The classic dataset does not reflect concept drift, new attack patterns or changing transaction behaviour over time.
The recorded threshold depends on the chosen cost matrix. Different business costs produce different operating points.
The project contains no live ingestion, monitoring, feedback loops or operational controls.
This is a learning and analysis project. Do not use the saved model or threshold for real-world decisions without proper validation and domain review.
Add continuous checks so shifts in transaction behaviour surface before model performance quietly degrades.
Capture true outcomes of flagged transactions so future training and threshold choices improve from real decisions.
Improve score calibration so cost calculations rest on better estimates of true fraud likelihood.
Package the best model behind a scored API with monitoring, audit logs and human review queues.
Finding the signal is only half the work. Explaining why a transaction was flagged and choosing a threshold under real cost assumptions turns a score into an actionable review policy.
Surface rare fraud without drowning in false alarms.
Use SHAP so analysts can see what the model is responding to.
Let business costs, not a default 0.5 threshold, set the operating point.
Treat the pipeline as a living system that must track drift and feedback.
Notebooks and source code.