{"id":26379920,"url":"https://github.com/gss-18/fraud-detection","last_synced_at":"2026-04-18T17:03:15.773Z","repository":{"id":282287554,"uuid":"948081712","full_name":"gss-18/Fraud-Detection","owner":"gss-18","description":"🚀 Credit Card Fraud Detection using Machine Learning \u0026 XGBoost. Evaluating models on an imbalanced dataset, using SMOTE, ROC-AUC analysis, and finding the best fraud detection approach. 📊🔍","archived":false,"fork":false,"pushed_at":"2025-03-13T18:28:39.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-13T19:38:00.159Z","etag":null,"topics":["classification","credit-card-fraud","data-science","fraud-detection","imbalanced-data","machine-learning","python","sklearn","smote","xgboost"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gss-18.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-13T18:06:23.000Z","updated_at":"2025-03-13T18:32:12.000Z","dependencies_parsed_at":"2025-03-13T19:48:15.709Z","dependency_job_id":null,"html_url":"https://github.com/gss-18/Fraud-Detection","commit_stats":null,"previous_names":["gss-18/fraud-detection"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gss-18%2FFraud-Detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gss-18%2FFraud-Detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gss-18%2FFraud-Detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gss-18%2FFraud-Detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gss-18","download_url":"https://codeload.github.com/gss-18/Fraud-Detection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976472,"owners_count":20377691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classification","credit-card-fraud","data-science","fraud-detection","imbalanced-data","machine-learning","python","sklearn","smote","xgboost"],"created_at":"2025-03-17T05:17:31.239Z","updated_at":"2026-04-18T17:03:10.723Z","avatar_url":"https://github.com/gss-18.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 💳 Credit Card Fraud Detection Using XGBoost  \n\n## 🚀 **Project Overview**\nThis project aims to detect fraudulent credit card transactions using machine learning. We experimented with multiple models and **found that the default XGBoost model performed the best**. Despite extensive hyperparameter tuning, default XGBoost provided the best balance of **precision, recall, and F1-score** for fraud classification.\n\n---\n\n## 📂 **Dataset Information**\n- **Dataset:** [Kaggle - Credit Card Fraud Detection](https://www.kaggle.com/datasets/mlg-ulb/creditcardfraud)  \n- **Total Transactions:** 284,807  \n- **Fraud Cases:** 492 (~0.17% of total transactions)  \n- **Non-Fraud Cases:** 284,315  \n- **Features:**  \n  - 30 anonymized features (`V1` to `V28`) derived using **PCA**  \n  - `Time`: Seconds elapsed since the first transaction  \n  - `Amount`: Transaction amount  \n  - `Class`: **Target variable (1 = Fraud, 0 = Non-Fraud)**  \n\n---\n\n## 🔬 **Project Methodology**\n1. **Data Preprocessing**\n   - Standardized the `Amount` feature.\n   - Used **SMOTE (Synthetic Minority Oversampling Technique)** to balance fraud cases in training data.\n\n2. **Model Training \u0026 Testing**\n   - Tried different models (**Logistic Regression, Decision Tree, LightGBM, Neural Networks**).\n   - **XGBoost outperformed all others**.\n   - Used **GridSearchCV** to fine-tune hyperparameters.\n\n3. **Final Model Selection**\n   - Compared **Default XGBoost vs Hyperparameter-Tuned XGBoost**.\n   - Surprisingly, **Default XGBoost gave better results**.\n   - **Final decision:** Use **default XGBoost** with minor threshold tuning.\n\n---\n\n## 📊 **Model Performance Comparison**\n| **Model**             | **Precision (Fraud)** | **Recall (Fraud)** | **F1-Score (Fraud)** |\n|---------------------|--------------------|-----------------|-----------------|\n| **Default XGBoost** | **0.79**           | **0.85**        | **0.82**        |\n| **Tuned XGBoost**   | **0.35**           | **0.88**        | **0.50**        |\n\n✅ **Default XGBoost was superior** because:  \n- It had a **higher F1-score (0.75 vs 0.50)**.  \n- It maintained a **strong fraud recall (0.86)** without excessive false positives.  \n- The tuned model had **very low precision (0.35)**, leading to **too many false alarms**.\n\n---\n\n## 🚀 **Final Model: Default XGBoost**\n### **🔹 Why Did Hyperparameter Tuning Fail?**\n- **`scale_pos_weight=7` hurt precision** by prioritizing fraud cases too much.  \n- **`max_depth=5 \u0026 n_estimators=150` overfitted the training data**.  \n- **Default settings provided a well-balanced model**, making extra tuning unnecessary.\n\n## 📈 **Final ROC-AUC \u0026 Precision-Recall Curve**\nAfter evaluating the model, we analyzed the **ROC-AUC Curve** and **Precision-Recall Curve** to measure the fraud detection performance.\n\n### **🔹 ROC-AUC Score (Receiver Operating Characteristic - Area Under Curve)**\n- **ROC-AUC Score:** **0.97**\n- A high **ROC-AUC score indicates strong discrimination** between fraud and non-fraud cases.\n- The model effectively **minimizes false positives while capturing fraudulent transactions**.\n\n### **🔹 Precision-Recall Curve Analysis**\n- **Average Precision (AP) Score:** **0.77**\n- This curve is especially useful for highly **imbalanced datasets** like fraud detection.\n- The model maintains **high precision at lower recall values**, ensuring fraud is detected efficiently.\n\n| **Metric**  | **Value** |\n|------------|----------|\n| **ROC-AUC** | 0.99 |\n| **PR AUC**  | 0.85 |\n\n✅ **These results confirm that the model successfully detects fraud with minimal false positives.**\n\n---\n\n## 🎯 **Key Takeaways**\n1️⃣ **Default XGBoost performed better than hyperparameter-tuned versions.**  \n2️⃣ **High recall (86%) ensures most fraud cases are detected.**  \n3️⃣ **Precision (67%) is reasonable, balancing fraud detection and false alarms.**  \n4️⃣ **Over-tuning `scale_pos_weight` and deep trees led to overfitting.**  \n5️⃣ **Sometimes, default settings work best!**  \n\n---\n\n## 📌 **Next Steps for Further Improvement**\n🔹 **Test Ensemble Learning** (XGBoost + LightGBM + Neural Network)  \n🔹 **Try a Hybrid Sampling Approach** (SMOTE + Undersampling)  \n🔹 **Experiment with AutoML-based tuning for even better performance**  \n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgss-18%2Ffraud-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgss-18%2Ffraud-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgss-18%2Ffraud-detection/lists"}