PROJECT / 02 ML · IMBALANCED LEARNING · SHAP
FRAUD DETECTION SYSTEM

Find the fraud. Understand the why.

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.

DOMAIN Financial Risk
CORE Imbalanced Learning
FOCUS Cost-Aware Decisions
02 FRAUD
ML SHAP COST
DETECT / EXPLAIN / DECIDE PORTFOLIO EXPLORE
01

How can a handful of fraudulent transactions be found in a sea of legitimate ones?

Most transactions are legitimate. A model that simply predicts “legitimate” most of the time can look accurate while missing the point entirely.

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.

THESIS

A prediction score is only useful when its consequences are understood. The real test is finding rare fraud without overwhelming analysts with false alarms.

02

Extreme imbalance forces every modelling choice.

The classic credit-card dataset provides anonymised PCA features alongside Time and Amount. Fraud is rare by design.
01

Transaction Records

PCA-transformed features plus Time and Amount, split into 227,845 training and 56,962 test transactions.

02

Extreme Imbalance

Fraud cases represent roughly 0.17 % of the data, so accuracy alone is a misleading success metric.

03

Four Notebooks

Preparation → Modelling → SHAP explainability → Cost-sensitive threshold evaluation form a complete analysis path.

DATA VIEW

Stratified splits, class weighting and SMOTE-style strategies keep the rare fraud examples visible throughout training and evaluation.

FRAUD RATE 0.17% extreme class imbalance
NOTEBOOKS 0 end-to-end analysis
EXPLAINABILITY SHAP global + local
03

From raw transactions to a cost-aware decision.

01

Prepare

Explore, scale, and create a stratified train/test split.

02

Model

Compare Logistic Regression, RF, XGBoost and LightGBM.

03

Explain

SHAP global importance and local force/waterfall plots.

04

Decide

Choose a threshold using explicit false-positive and false-negative costs.

PREPAREDATA
TRAINMODELS
EXPLAINSHAP
COSTTHRESHOLD
FLAGREVIEW
01

Imbalance Handling

Class weighting, stratified splits and resampling strategies keep the rare fraud class visible during training.

02

Proper Metrics

Precision, recall, F1, PR-AUC and ROC-AUC replace accuracy as the primary evaluation lens.

03

SHAP + Cost

Global and local explanations sit alongside a cost matrix so the operating threshold reflects real trade-offs.

04

What the checked-in experiment reports.

Illustration of imbalanced transaction data, model review, SHAP explanations, and cost-aware fraud decisions.
Conceptual project illustration; it is not live transaction data or a model output.

XGBoost with scale_pos_weight as the strongest performer.

Metrics describe the saved experiment. They are not a promise of future performance on live traffic.

01 PRECISION 0.872

High fraction of flagged transactions that are truly fraudulent.

02 RECALL 0.837

Strong ability to surface the rare fraud cases.

03 F1 0.854 · PR-AUC 0.879

Balanced detection quality under severe class imbalance.

04 ROC-AUC 0.979

Strong ranking ability across the full score spectrum.

05 THRESHOLD 0.64

Minimum-cost operating point under FN cost 150, FP cost 5, TP cost 10 (recorded test cost 9,160).

05

Where this analysis still has clear boundaries.

01

Anonymised Features

PCA-transformed columns limit domain interpretation even though SHAP can still rank their influence.

02

Static Dataset

The classic dataset does not reflect concept drift, new attack patterns or changing transaction behaviour over time.

03

Cost Assumptions

The recorded threshold depends on the chosen cost matrix. Different business costs produce different operating points.

04

No Production Stack

The project contains no live ingestion, monitoring, feedback loops or operational controls.

IMPORTANT

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.

06

Where a research pipeline can become operational.

01
DRIFT

Monitor feature and score distributions.

Add continuous checks so shifts in transaction behaviour surface before model performance quietly degrades.

02
FEEDBACK

Close the loop with analyst labels.

Capture true outcomes of flagged transactions so future training and threshold choices improve from real decisions.

03
CALIBRATION

Treat probabilities as probabilities.

Improve score calibration so cost calculations rest on better estimates of true fraud likelihood.

04
DEPLOYMENT

Move from notebooks to a service.

Package the best model behind a scored API with monitoring, audit logs and human review queues.

The project started with rare fraud labels. It became an exercise in making the decision cost explicit.

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.

01 DETECT

Surface rare fraud without drowning in false alarms.

02 EXPLAIN

Use SHAP so analysts can see what the model is responding to.

03 COST

Let business costs, not a default 0.5 threshold, set the operating point.

04 ITERATE

Treat the pipeline as a living system that must track drift and feedback.

Explore the investigation.

Notebooks and source code.