Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

💳 Credit Card Fraud Detection using Machine Learning

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.


📌 Project Overview

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.


🎯 Objectives

  • 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.

📂 Dataset

  • Source: Kaggle
  • File Used: fraudTest.csv

Dataset Features

Some important features include:

  • Transaction Amount
  • Merchant
  • Category
  • Gender
  • City
  • State
  • Latitude & Longitude
  • Merchant Location
  • City Population
  • Transaction Time
  • Fraud Label (is_fraud)

🛠️ Technologies Used

  • Python
  • Pandas
  • NumPy
  • Matplotlib
  • Seaborn
  • Scikit-learn
  • Jupyter Notebook

📊 Project Workflow

Dataset
      │
      ▼
Data Exploration
      │
      ▼
Data Cleaning
      │
      ▼
Label Encoding
      │
      ▼
Train-Test Split
      │
      ▼
Feature Scaling
      │
      ▼
Model Training
      │
      ├────────► Logistic Regression
      │
      └────────► Random Forest
                    │
                    ▼
Model Evaluation
                    │
                    ▼
Performance Comparison

📈 Models Used

1️⃣ Logistic Regression

A simple linear classification algorithm used as the baseline model.

2️⃣ Random Forest

An ensemble learning algorithm that combines multiple decision trees to improve prediction accuracy.


📏 Evaluation Metrics

The models were evaluated using:

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • ROC-AUC Score
  • Confusion Matrix

📊 Model Performance

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%

📷 Project Screenshots

Fraud Distribution

Fraud Distribution


Logistic Regression Confusion Matrix

Logistic Regression


Random Forest Confusion Matrix

Random Forest


ROC Curve

ROC Curve


Feature Importance

Feature Importance


💡 Key Findings

  • 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.

📁 Project Structure

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

🚀 How to Run

Clone the repository

git clone <repository-url>

Install dependencies

pip install -r requirements.txt

Open the notebook

jupyter notebook fraud_detection.ipynb

Dataset: Download the dataset from Kaggle and place fraudTest.csv in the project root before running the notebook.

🔮 Future Improvements

  • Handle class imbalance using SMOTE.
  • Perform hyperparameter tuning.
  • Use XGBoost and LightGBM.
  • Deploy the model using Streamlit or Flask.
  • Integrate real-time fraud prediction.

👨‍💻 Author

Asutosa Tiwari

If you found this project helpful, consider giving it a ⭐ on GitHub.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages