Team Ai
Apppublic

dark-ui/automl-fraud-detection

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

๐Ÿ›ก๏ธ AutoML-X โ€” Intelligent Fraud Detection System

Python FastAPI RandomForest SHAP SMOTE XGBoost License ![CI](https://github.com/Sujal-baghela/Automl-fraud-detection/actions/workflows/ci.yml) Tests Coverage


๐Ÿ“Œ Overview

AutoML-X is a production-ready, end-to-end machine learning system for credit card fraud detection. It automatically trains, evaluates, and selects the best model from 5 competing algorithms using cross-validation, applies feature engineering on raw transaction data, optimizes the decision threshold based on real business costs, and serves predictions through a FastAPI REST API with full SHAP explainability.

Built as a Minor Project at Madhav Institute of Technology and Science.


๐ŸŽฏ Key Results

MetricValue
๐Ÿ† Best ModelRandom Forest
๐Ÿ“ˆ CV ROC-AUC0.99999
๐Ÿ“Š Test ROC-AUC0.97482
๐ŸŽฏ Frauds Caught88 / 98 (89.8% Recall)
๐Ÿ’ฐ Minimum Business Cost$113,800
โšก Optimal Threshold0.20603 (cost-optimized)
๐Ÿ”ข Total Features35 (30 original + 5 engineered)
๐Ÿ” Imbalance HandlingSMOTE (50/50 balanced)
๐Ÿงช Test Suite285 tests passing
๐Ÿ“‹ CI/CDGitHub Actions โ€” lint + test on every push
๐Ÿ“Š Coverage99%

๐ŸŒ Live Demo

ServiceURL
FastAPI REST APIhttps://dark-ui-automl-x-fraud-detection.hf.space
Streamlit Dashboardhttps://dark-ui-automl-x-fraud-detection-8501.hf.space
MLflow UIhttps://dark-ui-automl-x-fraud-detection-5000.hf.space

๐Ÿ“Š Evaluation Reports

ROC Curve (AUC = 0.97482)

[image]

Confusion Matrix (Threshold = 0.20603)

[image]


๐Ÿ” SHAP Explainability

Feature Importance โ€” Mean |SHAP| (Top 20 Features)

[image]

Feature Impact Direction โ€” Beeswarm Plot

[image]

Top fraud indicators: V14, V4, V12, V10, V3 โ€” consistent with published research on this dataset.

๐Ÿ—๏ธ System Architecture

creditcard.csv
      โ”‚
      โ–ผ
 DataLoader โ”€โ”€โ–บ imbalance detection (0.17% fraud rate)
      โ”‚
      โ–ผ
 DataCleaner โ”€โ”€โ–บ remove duplicates, impute missing, log outliers
      โ”‚
      โ–ผ
 Feature Engineering (+5 derived features)
      โ”œโ”€โ”€ Hour          (fraud varies by time of day)
      โ”œโ”€โ”€ Night_txn     (10pmโ€“6am binary flag)
      โ”œโ”€โ”€ Amount_log    (log transform โ€” compresses skew)
      โ”œโ”€โ”€ Amount_zscore (how unusual is this amount)
      โ””โ”€โ”€ High_amount   (Amount > $1,000 binary flag)
      โ”‚
      โ–ผ
 SMOTE Oversampling โ”€โ”€โ–บ balanced training set (50/50)
      โ”‚
      โ–ผ
 AutoModelSelector โ€” 5 models compete via cross-validation
      โ”œโ”€โ”€ LogisticRegression    (ROC-AUC: 0.99812)
      โ”œโ”€โ”€ RandomForest          (ROC-AUC: 0.99999) โœ… selected
      โ”œโ”€โ”€ LightGBM_Balanced     (ROC-AUC: 0.99998)
      โ”œโ”€โ”€ LightGBM_HighRecall   (ROC-AUC: 0.99997)
      โ””โ”€โ”€ XGBoost_HighRecall    (ROC-AUC: 0.99993)
      โ”‚
      โ–ผ
 BusinessCostOptimizer โ”€โ”€โ–บ threshold = 0.20603
      โ”‚                    cost = $113,800
      โ–ผ
 best_model.pkl โ”€โ”€โ–บ FastAPI โ”€โ”€โ–บ /predict
      โ”‚                   โ””โ”€โ”€โ–บ /predict/batch
      โ”‚                   โ””โ”€โ”€โ–บ SHAP explanation per transaction
      โ–ผ
 DriftDetector โ”€โ”€โ–บ PSI + KS test on new data
      โ”‚
      โ–ผ
 ModelMonitor โ”€โ”€โ–บ SQLite logging + alert rules
      โ”‚
      โ–ผ
 AlertManager โ”€โ”€โ–บ Slack webhook + log file
      โ”‚
      โ–ผ
 MLflow โ”€โ”€โ–บ experiment tracking + model registry

๐Ÿ”ง New: Monitoring & Alerting

EndpointMethodDescription
/monitor/healthGETSystem health + DB status
/monitor/summaryGETRolling prediction statistics
/monitor/alertsGETAlert history
/monitor/check-alertsPOSTTrigger alert rule evaluation

Alert rules:

  • โ€”๐Ÿ”ด CRITICAL โ€” Fraud rate exceeds 30% in last 100 predictions
  • โ€”๐ŸŸก WARNING โ€” Average model confidence drops below 60%
  • โ€”๐ŸŸก WARNING โ€” Data drift detected (PSI โ‰ฅ 0.1 on 10%+ of features)

๐Ÿงช Experimentation Journey

RunTechniqueModelRecallCostOutcome
1SMOTERandomForest (30 features)90.8%$108,400Strong baseline
2BorderlineSMOTELightGBM84.7%$151,800Lower recall
3SMOTETomekLightGBM variants84.7%$157,200No improvement
4SMOTE + Feature Eng.LightGBM_Balanced88.8%$118,800Best Test AUC
5SMOTE + Feature Eng.RandomForest (35 features)89.8%$113,800โœ… Final

๐Ÿ’ฐ Business Cost Optimization

Total Cost = (Missed Frauds ร— $10,000) + (False Alarms ร— $200)

Final result at threshold 0.20603:
  10 frauds missed  ร—  $10,000  =  $100,000
  69 false alarms   ร—    $200   =   $13,800
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  Total minimum cost            =  $113,800

๐Ÿš€ Quick Start

bash
# 1. Clone
git clone https://github.com/Sujal-baghela/Automl-fraud-detection.git
cd Automl-fraud-detection

# 2. Install
pip install -r requirements.txt

# 3. Add dataset
# Download creditcard.csv from Kaggle โ†’ place at Data/creditcard.csv

# 4. Train
python -m Scripts.train

# 5. Run API
uvicorn app.api:app --reload --port 8000

# 6. Run Dashboard
streamlit run app/dashboard.py

# 7. Run MLflow
mlflow ui --port 5000

# 8. Docker (all services)
docker-compose up --build

๐ŸŒ API Endpoints

MethodEndpointDescription
GET/Health check
GET/model-infoModel metadata
POST/predictSingle prediction + SHAP
POST/predict/batchBatch prediction
GET/monitor/healthSystem health
GET/monitor/summaryRolling stats
GET/monitor/alertsAlert history

๐Ÿ“‚ Project Structure

automl-x/
โ”œโ”€โ”€ .github/workflows/ci.yml
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ api.py                  # FastAPI + monitoring integration
โ”‚   โ”œโ”€โ”€ dashboard.py            # Streamlit dashboard
โ”‚   โ””โ”€โ”€ universal.py
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ monitor.py              # ModelMonitor โ€” SQLite logging
โ”‚   โ”œโ”€โ”€ alerting.py             # AlertManager โ€” Slack + log file
โ”‚   โ”œโ”€โ”€ drift_detector.py
โ”‚   โ”œโ”€โ”€ fraud_system.py
โ”‚   โ”œโ”€โ”€ inference_engine.py
โ”‚   โ”œโ”€โ”€ model_selector.py
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_monitor.py         # 96 tests
โ”‚   โ”œโ”€โ”€ test_pipeline.py
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ best_model.pkl
โ”‚   โ””โ”€โ”€ drift_reference.json
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ supervisord.conf
โ”œโ”€โ”€ docker-compose.yml
โ””โ”€โ”€ requirements.txt

๐Ÿ“ฆ Tech Stack

CategoryLibrary
ML Modelsscikit-learn, LightGBM, XGBoost
Imbalanceimbalanced-learn (SMOTE)
ExplainabilitySHAP 0.50.0
APIFastAPI, Uvicorn
DashboardStreamlit
MonitoringSQLite, custom ModelMonitor
AlertingSlack webhook, log file
Experiment TrackingMLflow
DataPandas, NumPy, SciPy
VisualizationMatplotlib, Seaborn
Testingpytest, pytest-cov (99% coverage)
LintingRuff
CI/CDGitHub Actions

๐Ÿ‘ฅ Authors

Sujal Baghela โ€” @Sujal-baghela

Sameer Bhilware โ€” @SameerBhilware-ui

Institution: Madhav Institute of Technology and Science


๐Ÿ“„ License

MIT License