← All work
AcademicNovember to December 2025ENSTA (Brest Campus), big data project

Spark Fraud Detection

A distributed ML pipeline that hunts rare fraud in 284,807 transactions, where only 0.17% are fraudulent.

284,807transactions processed
0.17%fraud rate in the data
0.82fraud F1 with GBT on the full data

The need

Fraud is extremely rare, which makes accuracy misleading: a model that always answers “not fraud” scores 99.8% and catches nothing. Real transaction volumes also call for tools that scale beyond one machine’s memory.

What I owned

The full pipeline, from Spark ingestion and analysis through to training and evaluation.

The solution

Ingest
Spark DataFrameClass distribution check
Explore
Correlation matricesBoxplots per featureMissing value check
Prepare
VectorAssemblerStandardScaler80/20 splitClass weights
Train and evaluate
Logistic regressionGradient-boosted treesPR AUC and fraud F1
Each model was trained on both the full data and a reduced, more balanced subset.

How it was built

On the full data, correlations with fraud are washed out by the majority class. Comparing against a moderately balanced subset of 2,982 rows revealed which features really separate the classes.

Full data: the signal is hidden by the imbalance.
Balanced subset: strong correlations with fraud appear.

Results

ModelDataFraud precisionFraud recallFraud F1PR AUC
Logistic regressionFull0.110.890.200.63
Gradient-boosted treesFull0.900.760.820.82
Logistic regressionReduced0.900.890.900.95
Gradient-boosted treesReduced0.940.890.920.96
  • On the realistic full data, GBT performed best, with 74 of 98 frauds caught and only 8 false alarms out of nearly 57,000 legitimate transactions.
  • Weighted logistic regression shows the trade-off, catching more fraud (87 of 98) but raising 681 false alarms.
  • The reduced-data scores are higher, but they come from a test set that does not reflect the real fraud rate, so they should not be read as production performance.