Machine Learning · Classification Case Study

Credit Card Fraud Detection

Investigating machine learning approaches for identifying fraudulent transactions in a highly imbalanced dataset, where fraud represents only a very small proportion of transaction activity.

Python Pandas Scikit-learn XGBoost SMOTE & Resampling Optuna

Project Overview

This case study explores how machine learning can distinguish legitimate credit card transactions from fraudulent ones. The central challenge is severe class imbalance: a model can achieve high overall accuracy by predicting the majority class while failing to identify fraud. The project therefore focuses on data preparation, imbalance-handling strategies, model comparison and threshold selection, with particular attention to precision, recall and the trade-off between false alarms and missed fraud.

Credit Card Fraud Detection project banner

Explore the Project

Access the project documentation, analytical notebook and source code.

Project README

Review the project background, objectives, methodology and key information.

Read the README

Jupyter Notebook

Explore the data preparation, imbalance strategies, model experiments and evaluation.

View the notebook

Analytical Workflow

The project follows a structured classification workflow, with safeguards to keep model selection separate from final test evaluation.

01

Data Cleaning & Preparation

Remove duplicate records, prepare model features and scale numerical data using training data to help prevent data leakage.

02

Class Imbalance Strategies

Compare random oversampling, SMOTE, ADASYN, undersampling, Edited Nearest Neighbours and class weighting.

03

Model Comparison & Tuning

Compare classification approaches using precision, recall and F1-score, then tune the XGBoost model with Optuna.

04

Threshold Selection & Final Evaluation

Select a decision threshold using the validation precision-recall curve, then evaluate the selected model on the held-out test set.

Key Findings

XGBoost produced the strongest overall validation results among the approaches evaluated. The final test results show why performance must be assessed beyond accuracy.

98.6% Test precision
72.6% Test recall
0.836 Test F1-score

On the held-out test set, the selected model achieved 98.6% precision and 72.6% recall, with an F1-score of 0.836.

This means that most transactions flagged as fraud were genuinely fraudulent, while the model still missed some actual fraud cases. Threshold selection improved the validation precision-recall balance, but test recall was lower than validation recall.

The findings highlight the practical trade-off between false alarms and missed fraud in a highly imbalanced classification problem.

Back to Machine Learning Projects