{"id":30360538,"url":"https://github.com/yuvraj0412s/proactive-fraud-detection-using-machine-learning","last_synced_at":"2026-05-02T17:31:43.243Z","repository":{"id":308425812,"uuid":"1032780625","full_name":"yuvraj0412s/Proactive-fraud-detection-using-machine-learning","owner":"yuvraj0412s","description":"An end-to-end machine learning project for detecting financial fraud using LightGBM, featuring in-depth EDA, advanced feature engineering, and a focus on actionable business insights.","archived":false,"fork":false,"pushed_at":"2025-08-05T20:37:16.000Z","size":762,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-05T22:26:05.952Z","etag":null,"topics":["class-imbalance","classification-model","data-analysis","data-science","data-visualization","exploratory-data-analysis","feature-engineering","fintech","fraud-detection","jupyter-notebook","lightgbm","machine-learning","pandas","python","scikit-learn","smote"],"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/yuvraj0412s.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,"zenodo":null}},"created_at":"2025-08-05T20:16:20.000Z","updated_at":"2025-08-05T20:44:45.000Z","dependencies_parsed_at":"2025-08-05T22:26:08.503Z","dependency_job_id":"1a3ba0ea-07bb-4e85-9e75-341dc8c91538","html_url":"https://github.com/yuvraj0412s/Proactive-fraud-detection-using-machine-learning","commit_stats":null,"previous_names":["yuvraj0412s/proactive-fraud-detection-using-machine-learning"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/yuvraj0412s/Proactive-fraud-detection-using-machine-learning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0412s%2FProactive-fraud-detection-using-machine-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0412s%2FProactive-fraud-detection-using-machine-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0412s%2FProactive-fraud-detection-using-machine-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0412s%2FProactive-fraud-detection-using-machine-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuvraj0412s","download_url":"https://codeload.github.com/yuvraj0412s/Proactive-fraud-detection-using-machine-learning/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuvraj0412s%2FProactive-fraud-detection-using-machine-learning/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271166902,"owners_count":24710592,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["class-imbalance","classification-model","data-analysis","data-science","data-visualization","exploratory-data-analysis","feature-engineering","fintech","fraud-detection","jupyter-notebook","lightgbm","machine-learning","pandas","python","scikit-learn","smote"],"created_at":"2025-08-19T14:23:05.178Z","updated_at":"2026-05-02T17:31:43.206Z","avatar_url":"https://github.com/yuvraj0412s.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Proactive Fraud Detection using Machine Learning\n\n[![Language](https://img.shields.io/badge/Language-Python-blue.svg)](https://www.python.org/)\n[![Pandas](https://img.shields.io/badge/Pandas-150458?style=for-the-badge\u0026logo=pandas\u0026logoColor=white)](https://pandas.pydata.org/)\n[![Scikit-Learn](https://img.shields.io/badge/scikit--learn-%23F7931E.svg?style=for-the-badge\u0026logo=scikit-learn\u0026logoColor=white)](https://scikit-learn.org/)\n[![LightGBM](https://img.shields.io/badge/LightGBM-008000?style=for-the-badge\u0026logo=lightgbm\u0026logoColor=white)](https://lightgbm.readthedocs.io/en/latest/)\n[![Jupyter](https://img.shields.io/badge/Jupyter-F37626.svg?style=for-the-badge\u0026logo=Jupyter\u0026logoColor=white)](https://jupyter.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n---\n\n## 📖 Project Overview\n\nThis project presents a complete end-to-end solution for proactively detecting fraudulent financial transactions. Using a large-scale synthetic dataset from PaySim, a state-of-the-art **LightGBM machine learning model** was developed to predict fraud with high accuracy.\n\nThe goal extends beyond simple prediction; this project focuses on **interpreting the model's decisions** to derive actionable insights, culminating in a strategic, data-driven fraud prevention plan for a financial institution.\n\n### 💼 The Business Problem\n\nA financial company is facing challenges with a specific type of fraud where malicious actors gain control of customer accounts, transfer the entire balance to another account, and then cash out the funds. The objective is to build a system that can detect this behavior in real-time and provide a strategy to prevent these financial losses before they occur.\n\n---\n\n## ✨ Key Project Highlights\n\n*   **High-Performance Model:** The final LightGBM model successfully identifies **100% of the fraudulent transactions** in the test set.\n*   **Advanced Feature Engineering:** Created novel features like `errorBalanceOrig` to capture financial discrepancies, which proved to be the most powerful predictors of fraud.\n*   **Effective Imbalance Handling:** Successfully managed the extreme class imbalance (\u003e99:1) using the SMOTE technique to ensure the model learned fraud patterns effectively.\n*   **Actionable Insights:** Translated complex model outputs into a clear, tiered business strategy for real-time fraud prevention.\n\n---\n\n## 🛠️ Tech Stack \u0026 Libraries\n\n*   **Python 3.x:** The core programming language for the analysis.\n*   **Pandas:** For high-performance data manipulation and cleaning.\n*   **NumPy:** For numerical operations.\n*   **Matplotlib \u0026 Seaborn:** For comprehensive data visualization and EDA.\n*   **Scikit-learn:** For data preprocessing (`StandardScaler`, `train_test_split`) and model evaluation metrics.\n*   **Imbalanced-learn:** For handling the severe class imbalance using `SMOTE`.\n*   **LightGBM:** The high-performance gradient boosting framework used for the core modeling task.\n*   **Jupyter Notebook:** As the interactive development environment for analysis and documentation.\n\n---\n\n## 🔎 Exploratory Data Analysis (EDA)\n\nThe initial analysis revealed critical characteristics of the dataset that guided the entire modeling process.\n\n*   **Class Imbalance:** The dataset is extremely imbalanced, with fraudulent transactions making up less than 0.2% of the total data. This insight was crucial for choosing the right evaluation metrics and modeling techniques.\n\n  ![Class Distribution](assets/class_distribution.png)  \n\n*   **Correlation of Numerical Features:** A heatmap was generated to visualize the relationships between numerical variables. This clearly showed strong multicollinearity between account balance columns (`oldbalanceOrg`/`newbalanceOrig`), justifying their removal before modeling to prevent model instability.\n\n  ![Correlation Matrix of Numerical Features](assets/Correlation_matrix.png)  \n\n---\n\n## 🔬 Project Workflow\n\nThis project was executed following a structured, five-step data science workflow:\n\n1.  **Data Cleaning \u0026 EDA:** Loaded the 6.3 million row dataset, performed a detailed EDA, and handled multi-collinearity by dropping redundant features.\n\n2.  **Feature Engineering:** Engineered powerful new features to capture the \"digital fingerprint\" of fraud. The `errorBalance` features, which calculate the mathematical discrepancy in account balances post-transaction, were the most impactful.\n\n3.  **Model Building \u0026 Training:**\n    *   Preprocessed the data using `StandardScaler`.\n    *   Addressed class imbalance using `SMOTE` on the training data to prevent data leakage.\n    *   Trained a **LightGBM Classifier**, chosen for its speed and accuracy.\n\n4.  **Model Performance Evaluation:** As 'accuracy' is a misleading metric, the model was evaluated using superior metrics like the Precision-Recall Curve.\n\n5.  **Insight Extraction \u0026 Strategy:** Analyzed the model's feature importances to identify the key drivers of fraud and formulate a concrete business plan.\n\n---\n\n## 📈 Results \u0026 Performance\n\nThe model delivered outstanding performance, demonstrating its capability to be a highly effective tool for fraud prevention.\n\n*   **Recall (Fraud Class): 1.00** — The model successfully detected **100%** of all fraudulent transactions in the test set.\n*   **Precision-Recall AUC (AUPRC): 0.925** — An excellent score indicating high-quality classification across all thresholds.\n\nThe PR Curve below visually demonstrates the model's ability to maintain high precision as recall increases, confirming its robustness.\n\n![Precision-Recall Curve](assets/pr_curve.png)\n\n### Key Predictive Factors\n\nThe model learned that engineered features and transaction behaviors were more important than just the transaction amount itself.\n\n![Feature Importance](assets/feature_importance.png)\n\n---\n\n## 🚀 Actionable Recommendations\n\nBased on the model's insights, the following multi-layered prevention strategy is recommended:\n\n1.  **Implement Real-Time Scoring:** Deploy the model to score all `TRANSFER` and `CASH_OUT` transactions in real-time.\n2.  **Introduce a Dynamic, Risk-Based System:**\n    *   **High-Risk Score (\u003e0.90):** Automatically **BLOCK** the transaction.\n    *   **Medium-Risk Score (0.50 - 0.90):** **CHALLENGE** the user with Two-Factor Authentication. This is the key to safely managing potential false positives.\n    *   **Low-Risk Score (\u003c0.50):** **ALLOW** the transaction to proceed seamlessly.\n\nThis tiered approach maximizes security where it's needed most while protecting the experience for legitimate customers.\n\n---\n\n## ⚙️ How to Run This Project Locally\n\nTo replicate this analysis, please follow these steps:\n\n**1. Prerequisites:**\n*   Python 3.8+\n*   pip \u0026 virtualenv\n\n**2. Clone the repository:**\n```bash\ngit clone https://github.com/yuvraj0412s/Proactive-fraud-detection-using-machine-learning.git\ncd Proactive-fraud-detection-using-machine-learning\n```\n\n**3. Create and activate a virtual environment:**\n```bash\npython -m venv venv\nsource venv/bin/activate  # On Windows, use `venv\\Scripts\\activate`\n```\n\n**4. Install the required libraries:**\nI recommend creating a `requirements.txt` file for a seamless setup. Create one by running `pip freeze \u003e requirements.txt` and then use the command below.\n```bash\npip install -r requirements.txt\n```\nIf you don't have the file, you can install the main libraries manually:\n```bash\npip install pandas numpy matplotlib seaborn scikit-learn imbalanced-learn lightgbm jupyter\n```\n\n**5. Download the dataset:**\n*   Download the dataset from [a public source like Kaggle](https://www.kaggle.com/datasets/ealaxi/paysim1) and place the `Fraud.csv` file in the root directory of the project.\n\n**6. Run the Jupyter Notebook:**\n```bash\njupyter notebook \"Name of Your Notebook.ipynb\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuvraj0412s%2Fproactive-fraud-detection-using-machine-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuvraj0412s%2Fproactive-fraud-detection-using-machine-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuvraj0412s%2Fproactive-fraud-detection-using-machine-learning/lists"}