Full ML Engineering cycle for bank credit scoring: Training → MLflow Tracking → FastAPI → SHAP Explainability → Drift Monitoring → Docker
🔗 Live API: https://credit-scoring-ml-api.onrender.com/predict
| Metric | Value |
|---|---|
| ROC-AUC | Logged in MLflow per experiment |
| Algorithm | LightGBM + Class Imbalance handling |
| Decision threshold | 0.15 (configurable) |
| Dataset | Home Credit Default Risk (Kaggle) |
| Explainability | SHAP TreeExplainer (Top-5 factors) |
| Layer | Technology |
|---|---|
| Machine Learning | Python, Pandas, Scikit-Learn, LightGBM |
| Experiment Tracking | MLflow (autolog, Model Registry, SQLite backend) |
| Explainable AI | SHAP (TreeExplainer, Top-5 risk factors) |
| Backend | FastAPI, Uvicorn, Pydantic |
| Drift Monitoring | Evidently AI (Data Drift Detection) |
| Frontend | Streamlit (interactive scoring dashboard) |
| DevOps | Docker, Git |
| Audit Logging | SQLite (full prediction history) |
| Deployment | Render |
📂 Home Credit Dataset (Kaggle)
│
▼
🔬 src/train.py ──► MLflow autolog() ──► mlflow.db (SQLite)
│ │
│ (metrics, ROC-AUC,
│ hyperparams, artifacts)
▼
🚀 api.py (FastAPI)
│
├── lifespan: mlflow.lightgbm.load_model(RUN_ID)
│ ← dynamic model loading from Registry
│
├── /predict ──► SHAP TreeExplainer
│ └──► Top-5 decision factors
│ └──► log_request() ──► SQLite audit log
│
└── app.py (Streamlit UI) ──► visual scoring dashboard
📊 src/monitor_drift.py ──► Evidently AI ──► reports/data_drift_report.html
Модель не "зашита" в код — при старте сервер динамически загружает нужную версию из MLflow по RUN_ID. Это позволяет переключаться между версиями модели без изменения кода API:
mlflow.set_tracking_uri("sqlite:///mlflow.db")
ml_models["lgbm"] = mlflow.lightgbm.load_model(f"runs:/{RUN_ID}/model")Каждое решение по кредиту сопровождается объяснением — топ-5 факторов которые повлияли на результат. Это требование банковских регуляторов (BASEL III):
{
"probability_of_default": 0.73,
"decision": "Reject",
"explanation": [
{"feature": "AMT_CREDIT", "impact": +0.42},
{"feature": "DAYS_EMPLOYED", "impact": +0.31},
{"feature": "AMT_INCOME_TOTAL", "impact": -0.18},
{"feature": "DAYS_BIRTH", "impact": +0.15},
{"feature": "EXT_SOURCE_2", "impact": -0.12}
]
}src/monitor_drift.py сравнивает референсные и текущие данные по 5 ключевым фичам модели и генерирует HTML-дашборд с алертами о дрейфе. Симулируется сценарий кризиса (рост доходов и кредитов в 3x):
python src/monitor_drift.py
# → reports/data_drift_report.htmlКаждый /predict запрос логируется в SQLite: фичи клиента, вероятность дефолта, решение, timestamp. Полная воспроизводимость и аудируемость — обязательное требование для финансовых сервисов.
Download Home Credit Default Risk from Kaggle.
Place application_train.csv and application_test.csv in data/raw/.
pip install -r requirements.txtpython src/train.pyMLflow automatically saves hyperparameters, ROC-AUC metrics and model artifacts to mlflow.db.
mlflow server --host 127.0.0.1 --port 5000 --backend-store-uri sqlite:///mlflow.dbOpen http://localhost:5000, copy the best RUN_ID and paste it into api.py.
# Local
uvicorn api:app --reload
# Docker
docker build -t credit-risk-api .
docker run -p 8000:8000 credit-risk-apistreamlit run app.pypython src/monitor_drift.py
# Open reports/data_drift_report.html in browsercredit-risk-api/
├── src/
│ ├── train.py # Training + MLflow autolog
│ ├── database.py # SQLite prediction audit log
│ └── monitor_drift.py # Evidently AI Data Drift
├── models/ # Saved artifacts
├── notebooks/ # EDA and experiments
├── reports/ # Evidently HTML reports
├── api.py # FastAPI microservice
├── app.py # Streamlit UI
├── Dockerfile
├── requirements.txt
└── README.md
Part of a Fintech ML ecosystem:
- fraud-detection-api — Real-time fraud detection with Redis + A/B Testing
- fraud-gnn — Graph Neural Networks for fraud detection
- pfm-ai-assistant — Personal Finance Manager with AI advisor
💡 MLOps progression: this project covers the full cycle — training → experiment tracking → model registry → API → monitoring. That's exactly what senior ML Engineers do in production fintech systems.
Rashid Nurbekov — ML Engineer | Fintech & Generative AI | Almaty, Kazakhstan 🇰🇿