This project focuses on detecting fraudulent credit card transactions using different machine learning models.
It handles highly imbalanced data and provides an end-to-end pipeline for preprocessing, sampling, model training, and evaluation.
The workflow includes data scaling, oversampling/undersampling, hyperparameter tuning, and evaluation using metrics like F1-score and Precision-Recall AUC.
Models selection (configurable via the config files):
- Logistic Regression (with configurable hyperparameters and optional Grid Search)
- Random Forest Classifier (with configurable hyperparameters and optional Randomized Search)
- Voting Classifier (combining Logistic Regression and Random Forest)
Sampling & Scaling options:
- Robust scaler
- Standard Scaler
- Oversampling: SMOTE, RandomOverSampler
- Undersampling: RandomUnderSampler, NearMiss
- Hybrid: SMOTETomek
Evaluation options:
- f1-Score
- PR-AUC
- Confusion Matrix
- Best threshold for the model using PR Curve
- Custom threshold
All models and sampling methods can be configured through YAML configuration files, allowing flexible experimentation.
credit_fraud_detection/
│
├─ config/
│ ├─ config.yml
│ ├─ model_config.yml
│ └─ eval_config.yaml
│
├── data/
│ ├── train.csv
│ ├── val.csv
│ └── test.csv
│
├─ models/
│ ├──
│ └──
├── cradit_fraud_utils_helper.py
├── credit_fraud_train.py
├── credit_fraud_utils_data.py
├── credit_fraud_utils_eval.py
├── EDA.ipynb
├── model_test.py
└─ README.md
-
config/config.yaml: Contains data paths and data preprocessing & balancing configuration settingseval_config.yaml: Contains evaluation metrics configurationmodel_config.yaml: Contains model selection, and configuration settings specific to each trained models which is :- Hyperparameters
- Grid search
- randomized search
-
data/train.csv: The training dataset.val.csv: The validation dataset.test.csv: The test dataset.
-
models/: Directory for storing trained models, plots and the config files for the model. -
credit_fraud_train.py: Script to train models with optional sampling, scaling, and hyperparameter tuning. Saves trained models and thresholds. -
credit_fraud_utils-data.py: Contains functions and utilities for data preprocessing and Loading. -
credit_fraud_utils_helper.py: Helper functions for loading models, configuration files. -
credit_fraud_utils_eval.py: Evaluation functions including F1-score, precision-recall curves, confusion matrices, and threshold optimization. -
model_test.py: Script for evaluating the trained models on test data -
eda.ipynb: Jupyter Notebook for Exploratory Data Analysis (EDA) on the training dataset.

