σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
scikit-learn skill›Module 3 · Honest evaluation›Topic 3.7·~50 minAdvanced

Calibrating probabilities

Skill positionModule 3 of 4 · Topic 7 of 9
3.7 Calibrating probabilities
—Lab score— / 100Total XP—Streak—

When 80% should mean 80%

A probability forecast is calibrated when, among the days where it said p, the share of up days is about p. Ranking and calibration are different virtues: a model can order days well (high AUC) and still say 0.8 when the truth is 0.55. The simplest score of probabilities is the Brier score, 1/nΣ(pᵢ-yᵢ)², the mean squared error of the forecast; 0 is perfect, 0.25 is what you get by always saying 0.5. To see calibration, cut [0,1] into bins, and in each bin compare the mean predicted probability with the share of ones. That table is the reliability curve. Summing the gaps, weighted by the size of each bin, gives the expected calibration error: ECE=Σₖnₖ/n |ȳₖ-p̄ₖ|.

A random forest averages many trees, and averaging pulls probabilities away from 0 and 1 in an odd way: they are often too extreme where the trees agree by memorising noise. CalibratedClassifierCV fixes this by learning a small correction on held-out data. The 'sigmoid' method fits a logistic curve p'=1/(1+e^(-(a s+b))) to the model's scores (two numbers, stable), and 'isotonic' fits a free non-decreasing step function (more flexible, needs more data). With financial data the held-out folds must come later in time than the training folds, so pass cv=TimeSeriesSplit(3). On the last 30% of 5,344 SPY days, always predicting the base rate has a Brier score of 0.2473. The raw forest gets 0.2600 with an error of 0.095, its probabilities running from 0.15 to 0.83; after sigmoid calibration the Brier score is 0.2475 and the error is 0.0001. Calibration turned an overconfident model into an honest one, and the honest one is the base rate, because the forest has no skill.

  • Rank is not probability: a high AUC says nothing about whether 80% means 80%.
  • Brier score and reliability bins are the checks; the baseline to beat is the Brier score of the base rate.
  • Calibrate on later data: CalibratedClassifierCV(..., cv=TimeSeriesSplit(3)), sigmoid first, isotonic with more data.

Lab · what's graded

  • The Brier score10 pts
  • The reliability table25 pts
  • Calibration error15 pts
  • The forest10 pts
  • The calibrated forest20 pts
  • The calibration study20 pts
Explorer · lab-sl-21
▾ lab-sl-21
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-sl-21$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-sl-21 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes

Log in to run your code.

Every lecture is free to read. Create an account or log in to run code, run tests and submit this lab.

  • In-browser IDE with a bash terminal — nothing to install
  • Instant grading, XP and your place on the skill
Create an accountLog in
OR
Continue with GitHub