Credit Scoring and Default Prediction
Module: Fintech AI | Difficulty: Advanced
Logistic Regression
Credit Scorecard
Survival Model for Default
Evaluation
| Metric | Interpretation | |--------|---------------| | AUC-ROC | Discrimination | | Gini | | | KS | Maximum separation | | PSI | Population stability |
import numpy as np
from sklearn.linear_model import LogisticRegression
class CreditScorer:
def __init__(self):
self.model = LogisticRegression(penalty='l1', C=0.1)
def fit(self, X, y):
self.model.fit(X, y)
def predict_proba(self, X):
return self.model.predict_proba(X)[:, 1]
def score_to_odds(self, score, factor=20, offset=500):
odds = np.exp((score - offset) / factor)
return odds / (1 + odds)
def gini(self, y_true, y_pred):
from sklearn.metrics import roc_auc_score
return 2 * roc_auc_score(y_true, y_pred) - 1
def ks_statistic(self, y_true, y_pred):
from scipy.stats import ks_2samp
pos = y_pred[y_true == 1]
neg = y_pred[y_true == 0]
return ks_2samp(pos, neg).statistic
Research Insight: Credit scoring requires explainability β regulations (ECOA, FCRA) require that decisions be explainable. While ML models achieve higher AUC, logistic regression remains dominant because of its interpretability. SHAP values help explain complex models.