Skip to content

Priyesh-DS-Code/Credit-Card-Fraud-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Credit Card Fraud Detection Using Machine Learning

Overview

This project addresses the problem of detecting fraudulent credit card transactions using Machine Learning techniques. Credit card fraud detection is a highly imbalanced classification problem where fraudulent transactions account for only a small fraction of total transactions. The objective is to identify fraudulent activities while minimizing missed fraud cases.

The project evaluates multiple class imbalance handling techniques and compares their impact on model performance using a Random Forest classifier.


Business Problem

Financial institutions process millions of transactions daily, making manual fraud detection impractical. Missing fraudulent transactions can result in significant financial losses, while excessive false alarms may negatively impact customer experience.

The goal of this project is to build a reliable fraud detection model capable of identifying fraudulent transactions within an extremely imbalanced dataset.


Dataset

The dataset contains anonymized credit card transaction records.

Features

  • V1 – V28: PCA-transformed numerical features

  • Amount: Transaction amount

  • Class:

    • 0 → Legitimate Transaction
    • 1 → Fraudulent Transaction

Class Distribution

Class Percentage
Legitimate 99.83%
Fraudulent 0.17%

This severe class imbalance makes fraud detection particularly challenging and requires specialized handling techniques.


Project Workflow

1. Data Preprocessing

  • Removed duplicate records
  • Dropped the Time feature
  • Applied feature scaling using StandardScaler
  • Performed stratified train-test splitting

2. Outlier Detection

  • Implemented Interquartile Range (IQR) based outlier detection
  • Removed extreme observations to reduce noise

3. Model Validation

  • Stratified 5-Fold Cross Validation
  • Hyperparameter tuning using GridSearchCV
  • Recall used as the primary optimization metric

4. Imbalance Handling Techniques

The following approaches were evaluated:

  • Baseline Random Forest
  • Random Oversampling
  • Random Undersampling
  • SMOTE (Synthetic Minority Oversampling Technique)
  • SMOTE + Tomek Links
  • Class Weight Balancing

Model Performance

Model Recall Precision F1 Score
SMOTE 0.852 0.254 0.392
Random Oversampling 0.838 0.237 0.370
Class Weights 0.824 0.315 0.455
Baseline Random Forest 0.768 0.965 0.855
SMOTE + Tomek Links 0.754 0.915 0.826

Final Model

Random Forest with Class Weights

The Class Weight approach was selected as the final model because it achieved a strong balance between fraud detection capability and prediction reliability without generating synthetic data.

Final Metrics

Metric Score
Recall 0.824
Precision 0.315
F1 Score 0.455
Accuracy 0.9967
ROC-AUC 0.9105

Evaluation Metrics

Given the highly imbalanced nature of the dataset, model performance was evaluated using:

  • Recall
  • Precision
  • F1 Score
  • ROC-AUC Score
  • Precision-Recall Curve

Recall was prioritized because identifying fraudulent transactions is more critical than maximizing overall accuracy.


Technologies Used

Programming Language

  • Python

Data Analysis

  • Pandas
  • NumPy

Data Visualization

  • Matplotlib
  • Seaborn
  • Plotly

Machine Learning

  • Scikit-learn
  • Imbalanced-learn

Model Selection

  • Stratified K-Fold Cross Validation
  • GridSearchCV

Project Structure

Credit-Card-Fraud-Detection/
│
├── data/
│   └── creditcard.csv
│
├── notebooks/
│   └── fraud_detection.ipynb
│
├── requirements.txt
├── README.md
└── LICENSE

Key Takeaways

  • Addressed an extreme class imbalance problem in a real-world fraud detection scenario.
  • Compared multiple resampling and balancing techniques.
  • Implemented robust model validation using Stratified Cross Validation.
  • Performed systematic hyperparameter optimization.
  • Evaluated models using business-relevant metrics rather than relying solely on accuracy.

Author

Priyesh Kumar Kashyap

Machine Learning | Data Science

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages