Machine Learning - Model Evaluation & Calibration

Evaluating statistical learning models requires metrics suited to classification thresholds, ranking quality, and probability calibration.

Confusion Matrix & Classification Metrics

For binary classification with positive (11) and negative (00) classes:

Actual \ Predicted Predicted Positive Predicted Negative
Actual Positive (PP) True Positive (TPTP) False Negative (FNFN)
Actual Negative (NN) False Positive (FPFP) True Negative (TNTN)

Core Derived Metrics

  • Precision (Positive Predictive Value): Precision=TPTP+FP\text{Precision} = \frac{TP}{TP + FP}
  • Recall (Sensitivity / True Positive Rate): Recall=TPR=TPTP+FN\text{Recall} = \text{TPR} = \frac{TP}{TP + FN}
  • Specificity (True Negative Rate): Specificity=TNR=TNTN+FP\text{Specificity} = \text{TNR} = \frac{TN}{TN + FP}
  • False Positive Rate (Fall-out): FPR=1−Specificity=FPTN+FP\text{FPR} = 1 - \text{Specificity} = \frac{FP}{TN + FP}
  • F1F_1 Score (Harmonic Mean): F1=2⋅Precision⋅RecallPrecision+Recall=2TP2TP+FP+FNF_1 = 2 \cdot \frac{\text{Precision} \cdot \text{Recall}}{\text{Precision} + \text{Recall}} = \frac{2 TP}{2 TP + FP + FN}
  • FβF_\beta Score: Fβ=(1+β2)⋅Precision⋅Recallβ2⋅Precision+RecallF_\beta = (1 + \beta^2) \cdot \frac{\text{Precision} \cdot \text{Recall}}{\beta^2 \cdot \text{Precision} + \text{Recall}} Setting β=2\beta = 2 emphasizes recall; setting β=0.5\beta = 0.5 emphasizes precision.

Evaluation Curves

1. Receiver Operating Characteristic (ROC) & AUC

  • Axes: x-axis is FPR\text{FPR}, y-axis is TPR\text{TPR}.
  • Properties: Invariant to class imbalance because both TPR\text{TPR} and FPR\text{FPR} evaluate within their respective true class populations.
  • Area Under Curve (ROC-AUC): Probability that a randomly chosen positive example is ranked higher than a randomly chosen negative example. Random guessing yields AUC=0.5\text{AUC} = 0.5.

2. Precision-Recall (PR) Curve

  • Axes: x-axis is Recall\text{Recall}, y-axis is Precision\text{Precision}.
  • Properties: Highly sensitive to class imbalance. When negatives heavily outnumber positives (e.g., fraud detection at 0.1% incidence), the PR curve and PR-AUC provide a more realistic assessment than ROC-AUC.

3. Cumulative Gain & Lift

  • Lift: Ratio of positive responses found in the top k%k\% selected population compared to a random sample: Lift=P(Positive∣Selected)P(Positive)\text{Lift} = \frac{P(\text{Positive} | \text{Selected})}{P(\text{Positive})}

Model Probability Calibration

A model with a high ROC-AUC may still produce output scores that do not reflect true posterior probabilities P(Y=1∣x)P(Y=1|\mathbf{x}). For example, Gradient Boosted Decision Trees (GBDT) and Support Vector Machines (SVM) frequently produce uncalibrated scores that cluster away from extreme probabilities 00 and 11.

A model is well-calibrated if, among samples assigned predicted probability p^=0.80\hat{p} = 0.80, exactly 80% belong to the positive class:

P(Y=1∣P^=p)=pP(Y = 1 \mid \hat{P} = p) = p

Calibration Techniques

1. Platt Scaling (Univariate Logistic Regression)

Fits a scalar sigmoid transformation on raw model scores sis_i using an independent validation set:

P(Y=1∣s)=11+exp⁡(A⋅s+B)P(Y = 1 \mid s) = \frac{1}{1 + \exp(A \cdot s + B)}

Parameters A,B∈RA, B \in \mathbb{R} are optimized via maximum likelihood (cross-entropy). Platt scaling is parametric and robust against overfitting on smaller calibration sets.

2. Isotonic Regression

A non-parametric approach that fits a piecewise constant monotonic step function m(s)m(s):

min⁡m∑i=1N(yi−m(si))2subject to m(si)≤m(sj) whenever si≤sj\min_m \sum_{i=1}^N (y_i - m(s_i))^2 \quad \text{subject to } m(s_i) \le m(s_j) \text{ whenever } s_i \le s_j

Solved via the Pair-Adjacent Violators Algorithm (PAVA). It requires no parametric assumptions but demands larger calibration datasets to avoid overfitting.

3. Piecewise Linear Calibration

Partitions raw predictions into bins and fits monotonic linear slopes within each bin, guaranteeing a continuous, monotonically increasing calibrated curve.

Quantitative Calibration Metrics

  • Brier Score: Mean squared error between predicted probabilities pi∈[0,1]p_i \in [0, 1] and actual binary outcomes yi∈{0,1}y_i \in \{0, 1\}: BS=1N∑i=1N(pi−yi)2\text{BS} = \frac{1}{N} \sum_{i=1}^N (p_i - y_i)^2 Lower values indicate better calibration and sharpness.
  • Expected Calibration Error (ECE): Groups predictions into MM equal-width probability bins B1,…,BMB_1, \dots, B_M and measures the weighted average discrepancy: ECE=∑m=1M∣Bm∣N∣acc(Bm)−conf(Bm)∣\text{ECE} = \sum_{m=1}^M \frac{|B_m|}{N} \left| \text{acc}(B_m) - \text{conf}(B_m) \right|

Association Rule Metrics

For evaluating co-occurrence in market basket analysis and entity relationships:

  • Support: Probability of observing both items AA and BB: Support(A,B)=P(A∩B)\text{Support}(A, B) = P(A \cap B)
  • Confidence (Strength): Conditional probability that item BB appears given AA: Confidence(A→B)=P(B∣A)=P(A∩B)P(A)\text{Confidence}(A \to B) = P(B \mid A) = \frac{P(A \cap B)}{P(A)}
  • Lift: Ratio of observed joint probability to the expected probability under independence: Lift(A,B)=P(A∩B)P(A)P(B)\text{Lift}(A, B) = \frac{P(A \cap B)}{P(A) P(B)}
    • Lift=1\text{Lift} = 1: AA and BB are statistically independent.
    • Lift>1\text{Lift} > 1: Positive association (AA and BB co-occur more frequently than chance).
    • Lift<1\text{Lift} < 1: Negative association (substitution effect).
  • Leverage: Difference between joint probability and independent probability: Leverage(A,B)=P(A∩B)−P(A)P(B)\text{Leverage}(A, B) = P(A \cap B) - P(A) P(B)