Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛡️ FraudGuard — Credit Card Fraud Detection System

A complete ML project for detecting credit card fraud using four models: Logistic Regression, Random Forest, XGBoost, LightGBM


📁 Project Structure

fraud_detection/
├── app.py                  # Streamlit main app
├── train.py                # Model training pipeline
├── requirements.txt        # Python dependencies
├── data/
│   └── generate_data.py    # Synthetic data generator
├── models/                 # Saved models (created after training)
├── pages/
│   ├── home.py             # Overview page
│   ├── train_models.py     # Training page
│   ├── predict.py          # Single prediction page
│   ├── batch.py            # Batch prediction page
│   └── model_insights.py   # Charts & model comparison
└── utils/
    └── predictor.py        # Prediction utilities

🚀 Quick Start

1. Create a virtual environment (recommended)

python -m venv venv

# Windows
venv\Scripts\activate

# Mac / Linux
source venv/bin/activate

2. Install dependencies

pip install -r requirements.txt

⚠️ Requires Python 3.9–3.11. Python 3.12+ may have issues with some libraries.

3. Run the app

streamlit run app.py

The app opens at http://localhost:8501


🔄 Workflow

  1. Train Models page → Click "Start Training" (takes ~60–120 seconds)
  2. Single Prediction → Enter transaction features or generate a random sample
  3. Batch Prediction → Upload a CSV of transactions
  4. Model Insights → Compare ROC/PR curves, confusion matrices, feature importance

🤖 Models & Techniques

Model Key Hyperparameters
Logistic Regression C=0.1, class_weight=balanced
Random Forest 200 trees, max_depth=8, balanced
XGBoost 200 trees, scale_pos_weight=50
LightGBM 200 trees, class_weight=balanced

Imbalance handling: SMOTE oversampling on training set + class weights

Features: V1–V28 (PCA components), log(Amount), Hour of day


📊 Expected Performance (on synthetic data)

Model ROC-AUC F1
Logistic Regression ~0.94 ~0.65
Random Forest ~0.98 ~0.80
XGBoost ~0.98 ~0.82
LightGBM ~0.98 ~0.81

🔧 VS Code Tips

  • Install the Python extension
  • Select your venv interpreter: Ctrl+Shift+P → "Python: Select Interpreter"
  • Open integrated terminal: Ctrl+`

📝 Notes

  • The dataset is synthetic (generated automatically). To use real data, place creditcard.csv in the data/ folder with columns V1–V28, Amount, Time, Class.
  • Models are saved as .pkl files in the models/ folder after training.
  • Retraining overwrites existing models.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages