You're building an XGBoost regression model that predicts:
"How much credit can we safely give this loan applicant?"
Input: Application data, financial history, behavior data Output (y): A dollar amount (e.g., $10,000) — this is continuous, not a yes/no
Since we're predicting a number (not a class), we can't use AUC, KS, or accuracy. We need regression-specific metrics.
1️⃣ The Core Metrics: How to Measure "How Wrong" the Model Is
Think of these as different ways to ask: "How far off were our predictions?"
📊 The Five Key Metrics (Simplified)
Code
┌──────────────────────────────────────────────────────────────┐
│ │
│ Predicted: $8,000 Actual: $10,000 Error: -$2,000 │
│ │
│ Different metrics measure this gap differently: │
│ │
└──────────────────────────────────────────────────────────────┘
Metric
What It Tells You
Easy Example
RMSE
Punishes BIG mistakes more harshly
RMSE = $3,000 → occasional huge errors (like predicting $50K when answer is $10K)
MAE
Average error in dollars
MAE = $2,000 → typical prediction is $2K off
MAPE
Average error as a %
MAPE = 15% → predictions are typically 15% off
R²
% of variation the model explains
R² = 0.65 → model explains 65% of why limits differ
Spearman
How well rankings match (not exact $)
0.8 → applicants ranked high by model usually do get high limits
🔍 Quick Visual: RMSE vs MAE
Code
Actual limits: $10K, $10K, $10K, $10K
Predictions: $9K, $9K, $9K, $50K ← One big mistake!
MAE = average of |errors| = $11K (smoothed)
RMSE = sqrt(average of errors²) = $20K (BIG mistake stands out!)
→ Use RMSE when big errors are costly (like over-lending)
→ Use MAE when you want a fair average
💡 Why Each Metric Matters in Credit Context
Code
┌────────────────────────────────────────────────────────┐
│ │
│ RMSE → "Did we make any DISASTROUS predictions?" │
│ (Giving $50K to someone who can repay $10K) │
│ │
│ MAE → "What's our TYPICAL miss in dollars?" │
│ (Off by ~$2K on average) │
│ │
│ MAPE → "How proportional is our error?" │
│ ($1K miss on a $5K limit = bigger problem │
│ than $1K miss on a $50K limit) │
│ │
│ R² → "Is our model better than just guessing │
│ the average?" │
│ │
│ Spearman → "Do we at least rank people correctly?" │
│ (Even if dollars are slightly off) │
│ │
└────────────────────────────────────────────────────────┘
2️⃣ What's "Good Enough"? Industry Thresholds
These are typical benchmarks (varies by business, but useful guidelines):
Metric
Acceptable Range
Why It Matters
RMSE
≤ 15–25% of credit range
Prevents catastrophic over-lending
MAE
≤ 10–20% of credit range
Keeps typical errors within tolerance
MAPE
≤ 30–40%
Ensures fairness across small & large limits
R²
≥ 0.5 (≥ 0.4 for noisy data)
Model meaningfully explains differences
Spearman
≥ 0.6–0.7
Critical for ranking applicants into tiers
📌 Example Sanity Check
Code
Credit limits range from $0 to $50,000
✅ RMSE = $3,000 → 6% of range → GOOD
✅ MAE = $2,000 → 4% of range → GREAT
⚠️ MAPE = 35% → Borderline → OK
✅ R² = 0.65 → 65% explained → GOOD
✅ Spearman = 0.75 → Rankings solid → GOOD
Model status: APPROVED ✅
3️⃣ Why Rank Ordering Often Matters MORE Than Exact $$
Here's a crucial insight that surprises many people:
In credit risk, the EXACT predicted dollar amount usually gets adjusted by business rules anyway. What matters most is the RANKING — does the model correctly order applicants from low-risk to high-risk?
🎯 Visual Example
Code
┌──────────────────────────────────────────────────────────┐
│ │
│ Applicants and Model Predictions: │
│ │
│ Person A: Model predicts $8K, gets approved for $7K │
│ Person B: Model predicts $15K, gets approved for $14K │
│ Person C: Model predicts $25K, gets approved for $20K │
│ │
│ ✅ Exact $ may differ from approvals │
│ ✅ BUT the ORDER (A < B < C) is correct │
│ ✅ Business policy makes final $ adjustments │
│ │
│ → Spearman rank correlation captures this perfectly │
│ │
└──────────────────────────────────────────────────────────┘
Why This Matters for Regulators
Approval tiers (Tier 1, 2, 3) depend on relative ranking
Spearman correlation is often a regulatory requirement
A model with slightly worse RMSE but better Spearman is often preferred ✅
4️⃣ Stability Checks: Does the Model Hold Up Over Time?
Accuracy on test data isn't enough. You need to know:
"Will this model still work in 6 months when customer behavior shifts?"
Two Critical Stability Tests
🔄 PSI (Population Stability Index)
What it checks: Are your input features behaving similarly now vs when you trained?
Code
Training time: Today (6 months later):
Income distribution: Income distribution:
$30K-$50K: 40% $30K-$50K: 25% ← SHIFTED!
$50K-$80K: 40% $50K-$80K: 35%
$80K+: 20% $80K+: 40%
PSI = high → DANGER!
Population has changed → model may fail
PSI Score
Interpretation
< 0.10
✅ Stable — no action needed
0.10 – 0.25
⚠️ Slight shift — monitor
> 0.25
🚨 Major shift — retrain model
For regression: Apply PSI on binned features, not on the target value.
🎯 CSI (Characteristic Stability Index)
What it checks: Is the relationship between a feature and the target stable?
Code
Example: "Does income still predict credit limit the same way?"
Training: Income $50K → avg limit $15K
Today: Income $50K → avg limit $12K ← Relationship shifted!
For regression:
Bin the feature into groups
Calculate mean target per bin (training vs production)
let’s frame this in a churn prediction context, because that’s a very common case where people see IV, PSI, and CSI all being used, notice that the formulas look similar, but get confused about why they’re treated differently.
1️⃣ The setting — churn prediction
Target: churn_flag (1 = churned, 0 = stayed).
Feature: avg_monthly_usage (average minutes per month).
Goal: Build a model that predicts churn, and also monitor if the feature is stable over time.
We have:
Train set → Customers from Jan–Mar 2025
OOT1 → Customers from Apr 2025
OOT2 → Customers from May 2025
2️⃣ The same base formula — different contexts
The mathematical core of IV, PSI, and CSI is a weighted log ratio:
The difference is what those “fractions” mean and which datasets are compared.
3️⃣ Information Value (IV)
Question: Does this feature separate churners from non-churners in a single dataset?
Fractions:
= fraction of stayers in that bin (within train set)
= fraction of churners in that bin (within train set)
Data involved: Only one dataset (e.g., Train).
Use: Feature selection — keep features with high IV (e.g., > 0.02).
Understanding Variance Inflation Factor (VIF) — An Intuitive Guide
What is VIF?
The Variance Inflation Factor (VIF) is a measure that indicates how much a predictor variable is correlated with other predictors in your dataset. It’s a key tool for detecting multicollinearity—a condition where predictors are highly correlated, potentially causing instability in regression models.
Why Multicollinearity Matters
When predictors overlap in the information they provide:
The model struggles to determine which feature is truly influencing the target.
Coefficient estimates can become unstable and unreliable.
Interpretability suffers, making it harder to trust the model.
How VIF is Calculated (Intuitively)
Choose a predictor variable (e.g., X₁).
Regress X₁ against all the other predictors (X₂, X₃, …, Xₙ).
Essentially: “Can the other features predict X₁?”
Calculate R² — the proportion of variance in X₁ explained by the others.
Apply the formula:
VIF = 1 / (1 - R²)
Low R² → Denominator close to 1 → VIF ≈ 1 (low correlation).
High R² → Denominator small → VIF large (high correlation).
How to Interpret VIF Values
VIF Value
Meaning
1
No correlation with other features (ideal)
< 5
Acceptable
5–10
Moderate to high correlation — monitor closely
> 10
Severe multicollinearity — problematic
An Intuitive Example
Imagine two features: height and leg length.
If leg length is almost always a fixed fraction of height:
Regressing leg length on height would yield a very high R².
The VIF for leg length would be large, signaling redundancy.
Purpose of VIF in Modeling
Identifies redundant predictors.
Helps decide whether to drop or combine correlated features.
Improves model stability and interpretability.
Key Takeaway
Question VIF answers: “Can I predict this feature using the others?”
High VIF: Strong multicollinearity → unstable estimates.
Low VIF: Predictors are relatively independent → better modeling performance.
Understanding R² and VIF — From Model Fit to Multicollinearity
When building regression models, two concepts often come up together: R² (R-squared) and VIF (Variance Inflation Factor).
One measures how well your model fits the data, while the other checks for redundancy between predictors.
Let’s break them down intuitively and see how they connect.
1. What is R²?
R² — also known as the coefficient of determination — tells you how well your model’s predictions match the actual data.
R² = 1 → Perfect fit (model predictions match data exactly)
R² = 0 → Model explains none of the variation (as good as predicting the mean)
R² < 0 → Worse than just predicting the mean
What R² Really Measures
It represents the proportion of variance in the target variable explained by the model.
For example:
R² = 0.70 → 70% of the target’s variation is explained by the predictors.
How It’s Calculated
Where:
SS_res = Sum of squared residuals (errors between actual & predicted)
SS_tot = Total sum of squares (variance of actual values from the mean)
R² Interpretation Table
R² Value
Meaning
1
Perfect prediction
0.7
Explains 70% of variance
0
No predictive power
< 0
Worse than mean prediction
2. How R² Relates to VIF
The Variance Inflation Factor (VIF) uses R² behind the scenes to detect multicollinearity — when predictors are highly correlated with each other.
For each predictor, we run a regression of that predictor on all the other predictors.
We calculate R² for that regression.
VIF is then:
High R² ⇒ High VIF ⇒ High multicollinearity
3. Step-by-Step VIF Example
Imagine we have three predictors:
Height
Weight
Leg_Length
160
60
80
170
70
85
180
80
90
175
75
88
165
65
83
Let’s calculate VIF for Weight.
Step 1: Regress “Weight” on the Other Predictors
We fit:
Weight = a + b1*Height + b2*Leg_Length + error
Step 2: Calculate R²
Suppose we get R² = 0.95 — meaning Height and Leg_Length together explain 95% of Weight’s variance.
Step 3: Compute VIF
Interpretation: VIF of 20 is extremely high — Weight is almost redundant given the other two predictors.
VIF Summary Table
Variable
R² with others
VIF
Multicollinearity?
Height
0.80
5
Moderate
Weight
0.95
20
Severe
Leg_Length
0.70
3.33
Low/Moderate
4. Python Example
import pandas as pd
from statsmodels.stats.outliers_influence import variance_inflation_factor
# Example Data
df = pd.DataFrame({
'Height': [160, 170, 180, 175, 165],
'Weight': [60, 70, 80, 75, 65],
'Leg_Length': [80, 85, 90, 88, 83]
})
# Calculate VIF
X = df[['Height', 'Weight', 'Leg_Length']]
vif_data = pd.DataFrame()
vif_data['feature'] = X.columns
vif_data['VIF'] = [variance_inflation_factor(X.values, i) for i in range(X.shape[1])]
print(vif_data)