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.
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.
The dataset contains anonymized credit card transaction records.
-
V1 – V28: PCA-transformed numerical features
-
Amount: Transaction amount
-
Class:
- 0 → Legitimate Transaction
- 1 → Fraudulent Transaction
| Class | Percentage |
|---|---|
| Legitimate | 99.83% |
| Fraudulent | 0.17% |
This severe class imbalance makes fraud detection particularly challenging and requires specialized handling techniques.
- Removed duplicate records
- Dropped the
Timefeature - Applied feature scaling using StandardScaler
- Performed stratified train-test splitting
- Implemented Interquartile Range (IQR) based outlier detection
- Removed extreme observations to reduce noise
- Stratified 5-Fold Cross Validation
- Hyperparameter tuning using GridSearchCV
- Recall used as the primary optimization metric
The following approaches were evaluated:
- Baseline Random Forest
- Random Oversampling
- Random Undersampling
- SMOTE (Synthetic Minority Oversampling Technique)
- SMOTE + Tomek Links
- Class Weight Balancing
| 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 |
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.
| Metric | Score |
|---|---|
| Recall | 0.824 |
| Precision | 0.315 |
| F1 Score | 0.455 |
| Accuracy | 0.9967 |
| ROC-AUC | 0.9105 |
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.
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Plotly
- Scikit-learn
- Imbalanced-learn
- Stratified K-Fold Cross Validation
- GridSearchCV
Credit-Card-Fraud-Detection/
│
├── data/
│ └── creditcard.csv
│
├── notebooks/
│ └── fraud_detection.ipynb
│
├── requirements.txt
├── README.md
└── LICENSE
- 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.
Priyesh Kumar Kashyap
Machine Learning | Data Science