A simple FastAPI service that predicts Probability of Default (PD), converts it into a credit score (300–850 scale), and assigns a risk level.
pip install pipenvFrom inside the project root (credit_scoring_backend/):
pipenv install fastapi uvicorn pandas scikit-learn joblib numpyThis will:
- Create a virtual environment
- Generate
Pipfile - Generate
Pipfile.lock
pipenv shellYou should now see the virtual environment active in your terminal.
Ensure the dataset exists at:
data/UCI_Credit_Card.csv
Run the training script:
python train.pyThis will:
- Train a Logistic Regression pipeline
- Evaluate performance (ROC-AUC, confusion matrix, classification report)
- Save the trained model to:
models/credit_model.pkl
uvicorn main:app --reloadAPI base URL:
http://127.0.0.1:8000
Interactive documentation:
http://127.0.0.1:8000/docs
{
"LIMIT_BAL": 200000,
"AGE": 35,
"avg_pay_delay": 0.2,
"credit_utilization": 0.45,
"payment_ratio": 0.6
}{
"PD": 0.18,
"Credit_Score": 751,
"Risk_Level": "Low"
}score = 850 - (PD * 550)
Risk Levels:
- High: score < 650
- Medium: 650–749
- Low: 750+
.
├── app.py
├── train_credit_model.py
├── data/
│ └── UCI_Credit_Card.csv
└── models/
└── credit_model.pkl
- Train the model
- Start the API
- Send POST request to
/credit-score - Receive PD, Credit Score, and Risk Level