Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Credit Card Fraud Detection with SMOTE

A Python notebook implementation for detecting fraudulent credit card transactions using SMOTE (Synthetic Minority Over-sampling Technique) and machine learning models.

Overview

This project addresses the challenge of credit card fraud detection, where fraudulent transactions are significantly outnumbered by legitimate ones. The notebook implements advanced sampling techniques and machine learning algorithms to achieve accurate fraud detection despite severe class imbalance.

🎯 Key Features

  • Imbalanced Data Handling: Uses SMOTE to create synthetic samples of the minority class (fraudulent transactions)

  • Multiple Model Implementations:

    • Logistic Regression with hyperparameter tuning
    • Neural Network (Keras/TensorFlow)
  • Outlier Detection & Removal: Statistical analysis to identify and handle extreme outliers

  • Comprehensive Evaluation: Uses precision, recall, F1-score, and confusion matrices instead of accuracy alone

🎓 Methodology

Data Processing

  1. Feature scaling using RobustScaler
  2. Correlation analysis to identify important features
  3. Outlier detection and removal based on IQR (Interquartile Range)

SMOTE Implementation

  • Synthetic samples are generated only during cross-validation
  • Training set is oversampled while validation set remains unchanged
  • Prevents data leakage and overfitting

Model Training

1. Logistic Regression:

  • RandomizedSearchCV for hyperparameter optimization
  • L1/L2 regularization options
  • 5-fold Stratified Cross-Validation

2. Neural Network:

  • Sequential model with dropout layers
  • Binary classification with softmax activation
  • Adam optimizer with learning rate tuning

📊 Evaluation Metrics

Given the severe class imbalance, the following metrics are prioritized:

  • Precision-Recall Curve: Better indicator than ROC for imbalanced datasets
  • F1-Score: Harmonic mean of precision and recall
  • Confusion Matrix: Detailed breakdown of predictions
  • Average Precision Score: Summary metric for precision-recall curve

Results

The notebook demonstrates:

  • High recall (~86-93%) for detecting fraudulent transactions
  • Precision-recall tradeoff visualization
  • Comparison of model performance with and without outlier removal

Requirements

numpy
pandas
matplotlib
seaborn
scikit-learn
imbalanced-learn
tensorflow/keras

Usage

Load the credit card transaction dataset (creditcard.csv) Run all cells sequentially in the notebook Models are trained with cross-validation Evaluation metrics and visualizations are automatically generated

Dataset

The notebook expects a CSV file with anonymized credit card transaction features (V1-V28), Time, Amount, and Class (0=legitimate, 1=fraud).

Future Improvements

  • Ensemble methods (Random Forest, XGBoost)
  • Advanced anomaly detection techniques
  • Real-time prediction pipeline
  • Feature engineering for temporal patterns

📧 Contact

For questions or feedback, please open an issue on GitHub.


Note: Results may vary slightly due to random states in train-test splits and SMOTE sampling The notebook includes comparative analysis with and without outlier removal Cross-validation ensures robust model evaluation despite limited fraud samples

About

Python notebook for Credit Card fraud detection

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages