/api/credit_risk_score

Header
X-Customer-Api-Id: <uuid>
X-Secret: <secret>
Content-Type: application/json
Request Body Schema
{
  "test_size": float,            // optional (0 < value < 1), default = 0.2
  "applicants": [                // one per borrower
    {
      "id": string,              // unique applicant ID
      "features": {              // numeric or categorical
        "<feature_name>": number|string,
        …
      },
      "label": 0|1               // omit for pure scoring; required for training
    }
  ]
}
Example Request Body
// Example Training Request
{
  "test_size": 0.2,
  "applicants": [
    { "id": "app-001", "features": { "income": 55000, "age": 34, "country": "BR", "late_payments": 0 }, "label": 0 },
    { "id": "app-002", "features": { "income": 64000, "age": 29, "country": "US", "late_payments": 1 }, "label": 0 },
    // … up to 50 rows …
    { "id": "app-050", "features": { "income": 63000, "age": 23, "country": "UK", "late_payments": 0 }, "label": 1 }
  ]
}
// Example Scoring Request (no labels)
{
  "applicants": [
    { "id": "app-051", "features": { "income": 72000, "age": 45, "country": "CA", "late_payments": 2 } },
    { "id": "app-052", "features": { "income": 48000, "age": 30, "country": "BR", "late_payments": 3 } }
  ]
}
Example Response Body
// Example Response
{
  "auc": 1.0,
  "best_model": "LogisticRegression",
  "predictions": [
    {
      "id": "app-001",
      "probability": 0.0001,
      "shap_values": {
        "num__age": 2.21,
        "num__late_payments": -1.38,
        "num__income": -0.89,
        "cat__country_BR": -0.18,
        "cat__country_US": -0.11
      },
      "shap_interpretation": "PD 0.0% ⇒ LOW risk. age +2.2 ↑; late_payments -1.4 ↓; income -0.9 ↓; country_BR -0.2 ↓; country_US -0.1 ↓"
    },
    {
      "id": "app-002",
      "probability": 0.317,
      "shap_values": {
        "num__age": 7.59,
        "num__income": 0.52,
        "cat__country_US": 0.18,
        "cat__country_BR": 0.13,
        "num__late_payments": -0.13
      },
      "shap_interpretation": "PD 31.7% ⇒ MEDIUM risk. age +7.6 ↑; income +0.5 ↑; country_US +0.2 ↑; country_BR +0.1 ↑; late_payments -0.1 ↓"
    }
    // … other applicants …
  ],
  "interpretation": "AUC=1.0000 with LogisticRegression. Portfolio split: 9 HIGH / 2 MEDIUM / 39 LOW risk."
}
Description

• Rapidly prototype a Probability‐of‐Default model without MLOps. • Accepts mixed labeled/unlabeled JSON; auto‐encodes, trains bake-off (LogReg, RF, XGB, CatBoost), selects by AUC. • Outputs AUC, champion model, per‐applicant PDs with SHAP explanations, and a human summary.

Business Usage

1. POST historical applicants with labels → training + scoring + SHAP. 2. Store best_model for audit. 3. For daily scoring, resend same schema without labels. 4. Embed PDs into risk/pricing systems; archive SHAP outputs for compliance. 5. Monitor AUC drift; retrain when below threshold.

← Back to all routes