Financial Fraud Detection (FFD) is an end-to-end machine learning pipeline that identifies fraudulent credit card transactions. The project tackles one of the most persistent challenges in applied ML — extreme class imbalance — by combining a Generative Adversarial Network (GAN) with six supervised classifiers to produce a robust, high-accuracy fraud detector.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 Challenge of Fraud Detection
Real-world fraud datasets are inherently imbalanced. In the FFD dataset, only 492 out of 50,492 transactions are fraudulent — roughly 0.97% of all records. A naïve model that predicts “genuine” for every transaction would achieve over 99% accuracy while completely failing at its core purpose.| Class | Count | Share |
|---|---|---|
| Genuine (0) | 50,000 | ~99.03% |
| Fraudulent (1) | 492 | ~0.97% |
Pipeline Overview
The FFD notebook (Design_Project.ipynb) walks through a sequential eight-step pipeline:
- Import dependencies — Load all required libraries (TensorFlow/Keras, scikit-learn, XGBoost, LightGBM, and visualization tools).
- Load dataset — Read
Creditcard_dataset.csvinto a pandas DataFrame and inspect its shape and class distribution. - Data preprocessing — Drop rows with
NaNvalues, remove theTimecolumn, applyStandardScalertoAmount, split features (V1–V28+Amount) from the label (Class), and visualize the data with PCA. - Build the generator — Define
build_generator(), a neural network that maps random noise to synthetic fraud feature vectors using TensorFlow/Keras. - Build the discriminator — Define
build_discriminator(), a binary classifier that learns to distinguish real from synthetic fraud records. - Assemble the GAN — Combine generator and discriminator into a full GAN via
build_gan(generator, discriminator)and compile withadam/binary_crossentropy. - Train the GAN and generate synthetic data — Run 1,000 training epochs, monitor generator quality with PCA via
monitor_generator(), then generate 1,000 synthetic fraud samples withgenerate_synthetic_data(generator, 1000)and compare their distribution against real fraud records. - Train classifiers and evaluate — Train all six classifiers on the augmented (real + synthetic) dataset and evaluate each with classification reports and confusion matrices.
Classifiers
FFD trains and evaluates six supervised classifiers on the combined real + synthetic dataset:Random Forest
An ensemble of 100 decision trees (
n_estimators=100) with majority-vote predictions. Robust to outliers and highly interpretable via feature importances.Support Vector Machine
An RBF-kernel SVM (
kernel='rbf', gamma='scale') that finds the maximum-margin hyperplane separating genuine from fraudulent transactions.K-Nearest Neighbors
A distance-based classifier (
n_neighbors=5) that labels each transaction by majority vote among its five nearest neighbors in feature space.Naive Bayes
A
GaussianNB classifier that applies Bayes’ theorem with the assumption of Gaussian-distributed, conditionally independent features.XGBoost
A gradient-boosted tree ensemble (
XGBClassifier) known for high accuracy and speed on tabular data, with built-in regularization.LightGBM
A histogram-based gradient boosting framework (
LGBMClassifier) optimized for large datasets with fast training and low memory usage.Tech Stack
| Package | Version / Notes |
|---|---|
tensorflow | ==2.11 — required for Keras API compatibility |
visualkeras | Neural network architecture diagrams |
numpy | Numerical computations and array handling |
pandas | DataFrame operations and CSV I/O |
scikit-learn | Preprocessing, classifiers, and evaluation metrics |
seaborn | Confusion matrix heatmaps |
matplotlib | General-purpose plotting |
plotly | Interactive scatter plots for PCA visualization |
xgboost | XGBClassifier for gradient-boosted trees |
lightgbm | LGBMClassifier for histogram-based boosting |