Platt Scaling for Classifier Scores

easy
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 7. Everything before it counts as cleared.

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