A machine learning project that detects fraudulent credit card transactions using classification algorithms. The project compares Logistic Regression and Random Forest models to identify the best-performing model for fraud detection.
Credit card fraud is a major challenge in the financial industry. Since fraudulent transactions are very rare compared to genuine ones, the dataset is highly imbalanced. This project focuses on building and evaluating machine learning models that can accurately identify fraudulent transactions while minimizing false positives.
- Explore and analyze credit card transaction data.
- Preprocess the dataset for machine learning.
- Train multiple classification models.
- Compare model performance using various evaluation metrics.
- Identify the best model for fraud detection.
- Source: Kaggle
- File Used:
fraudTest.csv
Some important features include:
- Transaction Amount
- Merchant
- Category
- Gender
- City
- State
- Latitude & Longitude
- Merchant Location
- City Population
- Transaction Time
- Fraud Label (
is_fraud)
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Scikit-learn
- Jupyter Notebook
Dataset
│
▼
Data Exploration
│
▼
Data Cleaning
│
▼
Label Encoding
│
▼
Train-Test Split
│
▼
Feature Scaling
│
▼
Model Training
│
├────────► Logistic Regression
│
└────────► Random Forest
│
▼
Model Evaluation
│
▼
Performance Comparison
A simple linear classification algorithm used as the baseline model.
An ensemble learning algorithm that combines multiple decision trees to improve prediction accuracy.
The models were evaluated using:
- Accuracy
- Precision
- Recall
- F1 Score
- ROC-AUC Score
- Confusion Matrix
| Model | Accuracy | Precision | Recall | F1 Score | ROC-AUC |
|---|---|---|---|---|---|
| Logistic Regression | 99.59% | 0.00 | 0.00 | 0.00 | 84.85% |
| Random Forest | 99.83% | 93.48% | 60.14% | 73.19% | 98.95% |
- The dataset is highly imbalanced, with fraudulent transactions representing less than 1% of the total data.
- Accuracy alone is not a reliable metric for fraud detection.
- Logistic Regression failed to identify fraudulent transactions effectively.
- Random Forest significantly outperformed Logistic Regression across Precision, Recall, F1 Score, and ROC-AUC.
- Random Forest was selected as the best-performing model for this task.
credit-card-fraud-detection/
│
├── images/
│ ├── fraud_distribution.png
│ ├── confusion_matrix_logistic.png
│ ├── confusion_matrix_rf.png
│ ├── roc_curve.png
│ └── feature_importance.png
│
├── fraud_detection.ipynb
├── fraudTest.csv
├── requirements.txt
└── README.md
git clone <repository-url>pip install -r requirements.txtjupyter notebook fraud_detection.ipynbDataset: Download the dataset from Kaggle and place fraudTest.csv in the project root before running the notebook.
- Handle class imbalance using SMOTE.
- Perform hyperparameter tuning.
- Use XGBoost and LightGBM.
- Deploy the model using Streamlit or Flask.
- Integrate real-time fraud prediction.
Asutosa Tiwari
If you found this project helpful, consider giving it a ⭐ on GitHub.




