In real-world fraud detection, fraudulent events are rare by design — and that rarity creates a fundamental machine learning challenge. When a dataset contains vastly more examples of one class than another, standard classifiers tend to learn the easy answer: predict the majority class for every input. The result is a model that looks highly accurate on paper but is operationally useless, because it never actually flags any fraud.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Antisource/FFD/llms.txt
Use this file to discover all available pages before exploring further.
The Imbalance Problem
The FFD dataset contains 50,000 genuine transactions (Class = 0) and only 492 fraudulent transactions (Class = 1) out of 50,492 total records.Naive Classifier Accuracy
>99% — by predicting all transactions as genuine
Naive Classifier Fraud Recall
0% — zero fraudulent transactions caught
Why Standard Oversampling Falls Short
The most common approaches to class imbalance — random oversampling and SMOTE (Synthetic Minority Oversampling Technique) — have well-known limitations in high-dimensional fraud detection scenarios:- Random oversampling duplicates existing minority samples verbatim. This causes the classifier to memorise specific fraud records rather than learning generalizable fraud patterns, leading to overfitting on the minority class.
- SMOTE generates new samples by interpolating between existing minority-class neighbours in feature space. While more principled than duplication, SMOTE can produce unrealistic samples in high-dimensional, PCA-transformed spaces where linear interpolation may not respect the true data manifold. It also struggles when the minority class is very small (492 samples), as there are few neighbours to interpolate between.
The GAN Approach
FFD trains a Generative Adversarial Network (GAN) on the 492 real fraud samples. Once trained, the generator can produce arbitrarily many new synthetic fraud transactions that statistically resemble real fraud data — not by copying or interpolating, but by learning the underlying distribution. After training, 1,000 synthetic fraud samples are generated and combined with the original 492 real fraud records, bringing the combined fraud pool to 1,492 samples for the training phase of the downstream classifiers.- Sample noise — draw a random normal noise vector of shape
(num_samples, latent_dim)wherelatent_dimmatches the generator’s input dimension (29). - Generate samples — pass the noise through the trained generator to produce
num_samplessynthetic feature vectors. - Return data — the output is a NumPy array ready to be concatenated with the real fraud data.
Monitoring Synthesis Quality
During GAN training, themonitor_generator() function is called every 10 epochs to provide a visual check that the generator is producing realistic fraud-like data.
- Projects both real and synthetic fraud samples down to 2 principal components using
sklearn.decomposition.PCA. - Creates a combined DataFrame tagged with
"real"or"fake"labels. - Renders a scatter plot coloured by label, so you can visually assess whether synthetic samples overlap well with the real fraud cluster.