Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Credit Card Fraud Detection

A complete pipeline for EDA and model training to detect fraudulent credit card transactions using CatBoost and Optuna.


Project Overview

The goal of this project is to detect fraudulent credit card transactions using data analysis, class balancing techniques, and advanced machine learning models. The dataset comes from Credit Card Fraud Detection, containing 284,807 transactions, of which only 492 are frauds.


Classification Report

Class Precision Recall F1-Score Support
Legitimate (0) 0.9997 0.9996 0.9996 56864
Fraudulent (1) 0.7822 0.8061 0.7940 98
Accuracy 0.9993 56962
Macro avg 0.8909 0.9029 0.8968 56962
Weighted avg 0.9993 0.9993 0.9993 56962

Dataset Description

The dataset used in this project is the Credit Card Fraud Detection dataset, originally released by European cardholders in 2013. It contains real-world anonymized transactions made by credit cards over a two-day period.

Dataset Summary:

  • Total rows: 284,807 transactions
  • Fraudulent transactions: 492 (≈0.172%)
  • Non-fraudulent transactions: 284,315
  • Features: 30 columns (28 anonymized + Time + Amount)
  • Target column: Class
    • 0 — Legitimate transaction
    • 1 — Fraudulent transaction

Feature Overview:

Column Description
Time Seconds elapsed between the transaction and the first transaction in the dataset
Amount Transaction amount
V1–V28 PCA-transformed features (anonymized for privacy)
Class Target variable (1 = fraud, 0 = non-fraud)

The features V1 through V28 are the result of a PCA transformation and have no direct interpretable meaning. The Time and Amount features were not transformed and may require preprocessing.

Note on Class Imbalance:

This is a highly imbalanced classification problem. Fraudulent transactions make up less than 0.2% of the dataset, which makes it crucial to apply proper resampling or class weighting techniques during model training.


Repository Structure

.
├── data/
│   └── creditcard.csv              # Raw dataset
├── notebooks/
│   ├── 00-eda.ipynb                 # Exploratory Data Analysis
│   └── 10-model-training.ipynb      # Model training and hyperparameter tuning
├── models/
│   └── catboost_fraud_model.cbm     # Final trained model
├── requirements.txt
└── README.md

Key Techniques

1. EDA (Exploratory Data Analysis)

  • Distribution analysis
  • Outlier detection for Amount
  • Correlation heatmap (sns.heatmap)
  • Class imbalance inspection
  • Log-transformation of Amount

2. Class Imbalance Handling

  • SMOTE (Synthetic Minority Oversampling Technique) - didn't work
  • Stratified undersampling (optional) - didn't work
  • scale_pos_weight parameter in CatBoost

3. Modeling

  • CatBoost Classifier (efficient, handles categorical features)
  • Hyperparameter tuning with Optuna
  • Cross-validation using ROC AUC

4. Post-processing

  • Optimal threshold selection based on F1-score
  • Precision-Recall curve visualization
  • Error analysis (confusion matrix, FP/FN inspection)
  • Feature importance visualization

Libraries Used

  • pandas, numpy
  • matplotlib, seaborn
  • scikit-learn
  • catboost
  • optuna
  • imblearn - for SMOTE, didn't work

How to Run

  1. Install the dependencies:
    pip install -r requirements.txt
  2. Open and run the notebooks in the notebooks/ directory in order.

Results

  • Improved precision for the minority (fraud) class ≈ 0.78
  • AUC ≈ 0.99
  • Significant F1-score improvement using the optimized threshold
  • Final model saved at models/catboost_fraud_model.cbm

Possible Improvements

  • Try LightGBM or XGBoost for comparison
  • Add explainability (e.g. SHAP, LIME)
  • Deploy the model with Gradio or FastAPI
  • Dockerized deployment and inference with Triton

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages