This project implements an end-to-end credit scoring workflow with:
- model training (
logistic,decision_tree,random_forest) - model evaluation and metrics export
- FastAPI inference service (
/predict) - Streamlit dashboard for monitoring + manual predictions
data/german_credit_data.csv- input datasetsrc/train_credit_model.py- training + evaluation pipelinesrc/api.py- FastAPI prediction API (usesmodels/random_forest.joblib)app/dashboard.py- Streamlit monitoring and prediction UImodels/- trained model artifactsreports/- exported metrics per modelrequirements.txt- dependencies
The dataset may not always include a true repayment/default label.
Supported modes:
- Real target mode (recommended): provide a valid target column such as
Risk. - Demo mode: generate a proxy label with
--create-proxy-targetusingCredit amountand--proxy-threshold.
Proxy mode is for learning only and is not production-grade risk modeling.
Install dependencies:
pip install -r requirements.txtpython src/train_credit_model.py --data-path data/german_credit_data.csv --target-column Risk --model-type logisticpython src/train_credit_model.py --data-path data/german_credit_data.csv --create-proxy-target --model-type decision_treepython src/train_credit_model.py --data-path data/german_credit_data.csv --create-proxy-target --model-type random_forestpython src/train_credit_model.py --data-path data/german_credit_data.csv --create-proxy-target --model-type random_forest --decision-threshold 0.45Per model:
models/logistic.joblibmodels/decision_tree.joblibmodels/random_forest.joblib
Per model metrics:
reports/metrics_logistic.jsonreports/metrics_decision_tree.jsonreports/metrics_random_forest.json
Start FastAPI:
python src/api.pyHealth check:
curl http://127.0.0.1:8000/Predict endpoint:
curl -X POST http://127.0.0.1:8000/predict -H "Content-Type: application/json" -d "{\"Age\":35,\"Sex\":\"male\",\"Job\":2,\"Housing\":\"own\",\"Saving_accounts\":\"little\",\"Checking_account\":\"moderate\",\"Credit_amount\":5000,\"Duration\":24,\"Purpose\":\"radio/TV\"}"Response shape:
{
"risk_probability": 0.3124,
"decision": "Approve"
}Start Streamlit:
streamlit run app/dashboard.pyThe dashboard supports:
- model selection (
logistic,decision_tree,random_forest) - threshold control from sidebar
- performance cards and confusion matrix
- class distribution and CV stability view
- manual prediction form (calls API at
http://127.0.0.1:8000/predict) - downloadable metrics JSON and HTML snapshot report
train_credit_model.py exports:
- Accuracy
- Precision
- Recall
- F1
- ROC-AUC
- PR-AUC
- Confusion Matrix
- Classification Report
- CV ROC-AUC mean/std
- Train at least one model (preferably all 3 for dashboard switching).
- Start API server:
python src/api.py. - Start dashboard:
streamlit run app/dashboard.py. - Open Streamlit UI and test the Prediction page.