Author: Nisarg Patel
Date: 3rd January 2026
This project tackles the critical financial challenge of credit card fraud detection using advanced machine learning techniques (XGBoost) and Explainable AI (SHAP). Applied to a dataset of 1,000,000+ real-world credit card transactions, this solution implements a business-centric Cost-Benefit Analysis to optimize decision thresholds, achieving 96% fraud recall and an estimated $917,000 reduction in total business cost compared to a default classifier.
Credit card fraud results in billions of dollars in losses annually. Financial institutions face two competing risks:
- Fraud Loss: Direct financial loss from unauthorized transactions (False Negatives).
- Customer Friction (False Positives): Blocking legitimate transactions leads to lost revenue (interchange fees) and customer churn.
A model optimized solely for technical accuracy may fail to maximize profitability — especially at a fraud prevalence of only ~0.57%, where accuracy is a misleading metric. The business requires a solution that continuously balances these costs to find the optimal operating point.
We developed a comprehensive data pipeline and predictive model:
- Data Preprocessing: Handling severe class imbalance (0.57% fraud rate) and extensive feature engineering (13 engineered features including velocity checks, time-based patterns, behavioral profiling).
- Modeling: Training an XGBoost Classifier optimized for Area Under the Precision-Recall Curve (AUPRC) — the correct metric for highly imbalanced fraud data.
- Explainability: Utilizing SHAP (SHapley Additive exPlanations) to provide transparency for every fraud prediction, enabling compliance and trust.
- Optimization: Implementing a custom Threshold Optimization Strategy based on the financial weight of False Negatives vs. False Positives, sweeping thresholds to identify the minimum-cost operating point.
- Fraud Detection: Achieved 96% recall on the fraud class, ensuring the vast majority of fraudulent transactions are flagged before losses occur.
- Financial Impact: The cost-sensitive threshold of 0.54 reduced total projected business costs by an estimated $917,000 compared to default classification.
- Key Determinants: SHAP analysis identified transaction velocity and time-based behavioral features as the primary drivers of fraud predictions across 13 engineered features.
- Python: Core logic and analysis.
- Pandas & NumPy: Data manipulation and vectorization.
- XGBoost: Gradient boosted decision trees for high-performance classification.
- SHAP: Model interpretability.
- Matplotlib & Seaborn: Professional visualization.
/data # For dataset
/notebooks # Jupyter notebooks with full analysis and outputs
/visualizations # High-resolution charts and model metric plots
/docs # Project documentation including BRD
The datasets used in this project (fraudTrain.csv and fraudTest.csv) are sourced from the Sparkov Data Generation project on Kaggle. Due to their large size, they are not hosted directly in this repository's main view but are required for the analysis.
- Name: Credit Card Fraud Detection Dataset (Simulated)
- Source: Kaggle - Credit Card Fraud Detection
fraudTrain.csv: Training datafraudTest.csv: Testing data
Please download these files and place them in the data/ directory to run the notebook locally.
- Clone this repository.
- Install dependencies:
pip install -r requirements.txt - Download data (see
Sourcesection above) - Run the notebook in
/notebooks.