📅 Date: 27.07.2025
👤 Author: Juniyad Tamboli, Kapurhol, Pune
This project delivers a comprehensive, end-to-end machine learning pipeline to detect fraudulent transactions in financial data, leveraging the power of the XGBoost classifier. It covers everything from preprocessing to model deployment, with top-notch accuracy and AUC, ensuring robust fraud detection for real-world applications.
- 🔍 Accurate Fraud Prediction: Build a robust ML model for identifying fraudulent transactions.
- ⚖️ Imbalance Handling: Use SMOTE to boost recall for fraud cases (minority class).
- 🛠️ Model Optimization: Tune XGBoost for optimal ROC-AUC performance.
- 💡 Interpretability: Highlight and explain the most influential fraud features.
- 🚀 End-to-End Pipeline: Deliver a ready-to-deploy model and web application.
- 📄 File:
fraud_dataset.csv - 🔢 Records: ~10,000 transactions
- 🧩 Features:
- Categorical (encoded):
merchant_categorycustomer_locationdevice_type
- Numerical (scaled):
previous_transactionscustomer_ageamount
- 🚫 Dropped:
transaction_id,customer_id,timestamp
- Categorical (encoded):
- 🔠 Label Encoding: All categorical features
- 📏 Feature Scaling: Normalize numerical values (StandardScaler)
- ⚖️ Class Balancing: SMOTE for fraud rate <15%
- Algorithm: XGBoost Classifier
- Hyperparameter Tuning: GridSearchCV on:
n_estimators: [150,max_depth: [4, -learning_rate`: [0.03, 0.07, 0.1]
- Validation: Stratified 3-fold Cross-Validation
- Data Split: 80/20 stratified (class preservation)
precision recall f1-score support
0 0.9751 0.9985 0.9867 1963
1 0.9984 0.9745 0.9863 1962
Accuracy: 0.9865 3925
Macro avg: 0.9868 3925
Weighted avg: 0.9868 3925
- 🏅 ROC-AUC Score:
0.9971659708797549
{
'learning_rate': 0.1,
'max_depth': 8,
'n_estimators': 200,
'scale_pos_weight': 0.99
}| Rank | Feature | Importance |
|---|---|---|
| 🥇 | merchant_category | 0.31 |
| 🥈 | previous_transactions | 0.27 |
| 🥉 | customer_location | 0.18 |
| 4️⃣ | device_type | 0.14 |
| 5️⃣ | customer_age | 0.05 |
| 6️⃣ | amount | 0.03 |
A user-friendly Flask-based web interface enables real-time fraud detection:
- 🔑 Required Features:
merchant_categoryprevious_transactionscustomer_locationdevice_typecustomer_ageamount
- ⚡ Instant Results:
- Predicts Fraudulent or Not Fraudulent 🟢🔴 with a probability score!
- 🖥️ File Structure:
app.py– Flask serverindex.html– User interfaceFraud_Detection_System.joblib– Trained modelscaler.pkl– StandardScalerfraud_dataset.csv– Dataset reference
-
📦 Requirements
- Python 3.7+
- Libraries: flask, numpy, scikit-learn, xgboost, joblib
-
▶️ Run the Apppython app.py
Open your browser to
http://127.0.0.1:5000🚀 -
🗃️ Deployment
- Place
Fraud_Detection_System.joblib&scaler.pklin the working directory
- Place
🎉 Your fraud detection system is ready for use!
Built with XGBoost, the model demonstrates exceptional accuracy and transparency, fit for real-world banking and finance needs.
For questions or collaboration, reach out to the author.
👨💻 Author:
Juniyad Tamboli, Pune
Feel free to share, star, or reach out for partnerships! 🚀