← All projects

TAB · Data science project

Credit Card Fraud Detection

Catching card fraud while cutting the cost of false alarms

Lower cost than baseline
93%
Fraud caught (recall)
82.4%
Alerts that are fraud (precision)
75.0%
GitHub ↗

The problem

Only 0.172% of transactions are fraud: 492 out of 284,807. Flag too much and analysts drown in false alarms; flag too little and fraud gets through. So instead of chasing accuracy, this project scores every model on what it costs the bank: $124 for each missed fraud and $25 for each false alarm.

The data

Credit Card Fraud Detection dataset, ULB Machine Learning Group (Kaggle) ↗

284,807 transactions by European cardholders (September 2013), with 28 anonymized features plus time and amount

Approach

  1. Removed 1,081 duplicate transactions and added time-of-day and log-amount features.
  2. Compared five models: logistic regression with class weights, logistic regression with SMOTE oversampling, random forest, tuned XGBoost and a neural network.
  3. Judged each model by its total business cost, along with ROC-AUC, PR-AUC, precision and recall.
  4. Tested 99 decision thresholds for the random forest to find the cheapest one, and explained its predictions with SHAP.

Results

At a threshold of 0.13, the random forest cut total cost from $58,584 (the baseline logistic regression) to $4,075, a 93% reduction. It catches 82.4% of fraud, and 75.0% of its alerts are real fraud (ROC-AUC 0.954). The baseline caught slightly more fraud but raised 2,264 false alarms; the final model raises 39.

Bar chart of total cost: $58,584 for the baseline logistic regression and $4,075 for the optimized random forest, a saving of $54,509.
Total cost on the test set: the baseline model against the threshold-tuned random forest.

What I'd do next

  • Try autoencoders, which learn what normal transactions look like and flag the ones that don't fit.
  • Serve the model through a REST API for real-time scoring.

Tools

  • Python
  • scikit-learn
  • XGBoost
  • TensorFlow
  • imbalanced-learn
  • SHAP
  • pandas

View code on GitHub ↗