Skip to main content

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.

With synthetic fraud samples produced by the GAN, the pipeline combines them with the original transaction data to create a balanced training set. Six diverse classifiers — spanning ensemble methods, kernel methods, instance-based learning, probabilistic models, and gradient boosting — are then trained on this augmented dataset so their results can be compared fairly under identical conditions.

Combining Real and Synthetic Data

The GAN output (synthetic fraud transactions) is concatenated with the real fraud data from the original dataset. A label column encodes the source. Both the synthetic and real fraud DataFrames are combined, shuffled, and then their labels are encoded before training:
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.utils import shuffle

# Generate 1000 synthetic fraud points from the trained generator
synthetic_data = generate_synthetic_data(generator, 1000)
df = pd.DataFrame(synthetic_data)
df['label'] = 'fake'

# Real fraud data (dropping the Class column)
df2 = data_fraud.drop('Class', axis=1)
df2['label'] = 'real'
df2.columns = df.columns

# Concatenate real and synthetic fraud data
combined_df = pd.concat([df, df2])

# Shuffle to remove any ordering artefacts
combined_df = combined_df.sample(frac=1).reset_index(drop=True)

# Encode labels: 'fake' -> 0, 'real' -> 1
label_encoder = LabelEncoder()
combined_df['label'] = label_encoder.fit_transform(combined_df['label'])

Train / Test Split

The combined and shuffled dataset is divided into training and test subsets using scikit-learn’s train_test_split. A fixed random_state guarantees reproducibility across all six models:
from sklearn.model_selection import train_test_split

x_combined = combined_df.drop("label", axis=1)
y_combined = combined_df["label"]

x_train, x_test, y_train, y_test = train_test_split(
    x_combined, y_combined,
    test_size=0.2,
    random_state=42
)

print(f'Training samples : {x_train.shape[0]}')
print(f'Test samples     : {x_test.shape[0]}')

Training the Classifiers

Each of the six classifiers is trained on the same (x_train, y_train) split so that evaluation results are directly comparable. Explore the individual model pages for architecture details, hyperparameter choices, and per-model performance breakdowns:

Random Forest

An ensemble of decision trees that reduces variance through bagging and random feature subsampling.

SVM

Support Vector Machine with an RBF kernel that finds the maximum-margin hyperplane separating fraud from genuine transactions.

KNN

K-Nearest Neighbours classifies each test sample by majority vote among its K closest training points.

Naive Bayes

Gaussian Naive Bayes models each feature as an independent Gaussian distribution conditioned on the class label.

XGBoost

Extreme Gradient Boosting builds an additive ensemble of shallow trees with regularisation to prevent overfitting.

LightGBM

Light Gradient Boosting Machine uses histogram-based splits and leaf-wise growth for fast, memory-efficient training.
The training call follows the same pattern for every classifier:
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
import xgboost as xgb
import lightgbm as lgb

# Model 1: Random Forest
rf_model = RandomForestClassifier(n_estimators=100, random_state=42)
rf_model.fit(x_train, y_train)
rf_predictions = rf_model.predict(x_test)

# Model 2: Support Vector Machine (SVM)
svm_model = SVC(kernel='rbf', gamma='scale', random_state=42)
svm_model.fit(x_train, y_train)
svm_predictions = svm_model.predict(x_test)

# Model 3: K-Nearest Neighbors (KNN)
knn_model = KNeighborsClassifier(n_neighbors=5)
knn_model.fit(x_train, y_train)
knn_predictions = knn_model.predict(x_test)

# Model 4: Naive Bayes
nb_model = GaussianNB()
nb_model.fit(x_train, y_train)
nb_predictions = nb_model.predict(x_test)

# Model 5: XGBoost
xgb_model = xgb.XGBClassifier(random_state=42)
xgb_model.fit(x_train, y_train)
xgb_predictions = xgb_model.predict(x_test)

# Model 6: LightGBM
lgb_model = lgb.LGBMClassifier(random_state=42)
lgb_model.fit(x_train, y_train)
lgb_predictions = lgb_model.predict(x_test)
Why shuffle before training?After concatenation the dataset is ordered — all synthetic data comes first, followed by real fraud. Feeding this ordered array directly into train_test_split would introduce ordering bias: the model could see only one class for long stretches, disrupting gradient updates in neural components and distorting cross-validation folds.Calling sample(frac=1) before splitting ensures that every mini-batch and every fold contains a representative mix of both classes, leading to more stable training and unbiased evaluation.

Build docs developers (and LLMs) love