Platt Scaling for Classifier Scores

easy
Unit 6 · Kernels0/3 to milestone

SVMs and boosted trees output scores, not probabilities. Platt scaling fits a 1-D logistic regression on held-out scores: P(y=1∣s)=σ(as+b)P(y = 1 \mid s) = \sigma(a s + b).

Implement:

  • fit_platt(scores, labels, iters=50): find a and b by Newton's method on the log loss, starting from a = 0 and b = log((pos + 1) / (neg + 1)). Return (a, b).
  • platt_predict(a, b, scores)
  • log_loss(probs, labels, eps=1e-12): the mean binary cross-entropy, clipping probabilities to [eps, 1 - eps]
#calibration#classification#logistic-regression2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Platt Scaling for Classifier Scores · TechGradify