A comprehensive machine learning system for African credit scoring with production-ready API deployment, optimized model training, monitoring, and persistence for audit.
# Credit Scoring System
A comprehensive machine learning system for African credit scoring with production-ready API deployment, optimized model training, monitoring, and persistence for audit.
## 📋 Overview
This system provides an end-to-end solution for credit scoring in African markets, featuring:
- **Hybrid Data Strategy**: Real Lending Club credit data (50K+ records) + synthetic mobile money features
- **Advanced ML Models**: Optimized XGBoost with SMOTEENN (AUC-ROC ~0.77)
- **FastAPI REST API**: Production-ready API with comprehensive documentation
- **Real-time Scoring**: Sub-second prediction response times
- **Explainable AI**: SHAP-based decision explanations for regulatory compliance
- **Health Monitoring**: Service health checks and performance metrics
- **Request Tracking**: Request ID tracking and error handling
## 🏗 Architecture
### 1. System Components (Pictorial Flow)
```
├── Credit Scoring System
│ ├── Data Pipeline (ETL)
│ ├── ML Training & Optimization
│ ├── Model Deployment (API)
│ ├── Monitoring & Alerting
│ └── Data Persistence
```
### 2. Request Logic (Process Flow)
1. **Request Ingestion**: Client sends applicant data via `POST /predict`.
2. **Feature Pipeline**: The `FeatureEngineer` transforms raw data into ML-ready vectors.
3. **Inference**: The `XGBoost` model computes the default probability and risk class.
4. **Explanation**: `SHAP` values are generated to explain the top driving factors of the score.
5. **Persistence**: The request and result are logged to `SQLite` via an async background task.
6. **Monitoring**: Real-time drift detection calculates Z-scores for inputs and distribution shifts for outputs.
7. **Response**: Final score, risk level, and behavioral explanations are returned to the client.
## 🚀 Quick Start
### Prerequisites
- **Python**: 3.9 or higher
- **Docker**: Latest version (for containerized deployment)
- **Git**: For cloning the repository
### 1. Clone Repository
```bash
git clone https:/ …