σμ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.6·~50 minAdvanced

Hyperparameter search without overfitting

Skill positionModule 3 of 4 · Topic 6 of 6
3.6 Hyperparameter search without overfitting
—Lab score— / 100Total XP—Streak—

The winner of a search is flattered

A hyperparameter search tries many settings, scores each on validation data and keeps the best. The trouble is that the best score of many noisy scores is biased upward, even if no setting has any skill. If NNN settings each have a pure-noise score with standard deviation σ\sigmaσ, the expected best one is about σ×zN\sigma\times z_Nσ×zN​, where z10=1.54z_{10}=1.54z10​=1.54 and z100=2.51z_{100}=2.51z100​=2.51. With an IC noise of σ=0.02\sigma=0.02σ=0.02, the winner of 100100100 useless settings looks like 0.0500.0500.050, a respectable signal that does not exist. Reporting the validation score of the winner as its performance is therefore optimistic, and the more settings you try, the worse it gets.

E[max⁡i≤Nsi]≈σ zN,z10=1.54,z100=2.51;K⋅C,Ko (KiC+1)E\left[\max_{i\le N}s_i\right]\approx\sigma\,z_N,\qquad z_{10}=1.54,\quad z_{100}=2.51;\qquad K\cdot C,\qquad K_{o}\,(K_{i}C+1)E[i≤Nmax​si​]≈σzN​,z10​=1.54,z100​=2.51;K⋅C,Ko​(Ki​C+1)(1)

There are three honest remedies. First, keep a test set that the search never sees and report only its score. Second, use nested cross-validation: an outer loop sets aside a test fold, and inside each outer training set an inner loop runs the search. The outer scores measure the whole procedure, search included. Third, shrink the search: fewer settings, coarser grids and settings that matter. With KoK_oKo​ outer folds, KiK_iKi​ inner folds and CCC candidates, nested validation needs Ko(KiC+1)K_o(K_iC+1)Ko​(Ki​C+1) fits, so budget for it. And before you search, ask whether the setting can matter at all.

Counting and a real gridTwenty candidates with 555 folds cost 100100100 fits, plus one final refit. Nested validation with 555 outer folds, 333 inner folds and 202020 candidates costs 5×(3×20+1)=3055\times(3\times20+1)=3055×(3×20+1)=305 fits. The best of 100100100 useless settings is expected at 2.51×0.02=0.0502.51\times0.02=0.0502.51×0.02=0.050, and the best of 101010 at 1.54×0.02=0.0311.54\times0.02=0.0311.54×0.02=0.031. If your winner scores 0.0600.0600.060, only 0.060−0.050=0.0100.060-0.050=0.0100.060−0.050=0.010 is left to explain. On the real monthly stock panel, ridge has no setting to tune: the information coefficient is 0.0330.0330.033 for every α\alphaα from 0.010.010.01 to 10410^{4}104. Five tree depths from 111 to 101010 give IC between −0.010-0.010−0.010 and 0.0130.0130.013, and the best, 0.0130.0130.013, is about one standard error (0.21/257=0.0130.21/\sqrt{257}=0.0130.21/257​=0.013) from zero.
  • The max of noise is not noise: the best of many useless settings looks like skill.
  • Nested validation scores the whole procedure, search included, for Ko(KiC+1)K_o(K_iC+1)Ko​(Ki​C+1) fits.
  • Compare with the noise: a gain smaller than one standard error is not a finding.

Lab · what's graded

  • The best of 100 useless settings15 pts
  • The best of 1010 pts
  • Fits of a grid search10 pts
  • Fits of nested validation15 pts
  • What is left to explain10 pts
  • Which search is honest10 pts
  • Nested validation10 pts
  • Why the winner's score is inflated20 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

Each of 100100100 useless settings has an IC with noise standard deviation 0.020.020.02. The expected best is σzN\sigma z_NσzN​ with z100=2.51z_{100}=2.51z100​=2.51. What is it? Give three decimals.

m=m =m=accepted: ± 0.001
2Numeric answer10 ptsNot answered

With only N=10N=10N=10 useless settings, z10=1.54z_{10}=1.54z10​=1.54 and σ=0.02\sigma=0.02σ=0.02. What is the expected best IC? Give three decimals.

m=m =m=accepted: ± 0.001
3Numeric answer10 ptsNot answered

A grid search tries C=20C=20C=20 candidates with K=5K=5K=5 folds each. How many fits does it run, not counting a final refit?

n=n =n=accepted: ± 0.01
4Numeric answer15 ptsNot answered

Nested validation has Ko=5K_o=5Ko​=5 outer folds, Ki=3K_i=3Ki​=3 inner folds and C=20C=20C=20 candidates, plus one refit per outer fold. How many fits are needed, Ko(KiC+1)K_o(K_iC+1)Ko​(Ki​C+1)?

n=n =n=accepted: ± 0.01
5Numeric answer10 ptsNot answered

Your winner scores an IC of 0.0600.0600.060 and the expected best of 100100100 useless settings is 0.0500.0500.050. How much of the score is above what luck alone would give? Give three decimals.

x=x =x=accepted: ± 0.001
6Choice10 ptsNot answered

Which procedure gives an honest estimate of how the tuned model will do on new data?

7Order the steps10 ptsNot answered

Put the steps of nested cross-validation in order.

Drag to reorder, or focus an item, press Space to lift it, the arrow keys to move it and Space to drop it.

  1. 1Score the refitted model on the outer test fold
  2. 2Set aside an outer test fold
  3. 3Refit the best setting on the whole outer training set
  4. 4Search the settings with an inner cross-validation on the outer training data
8Explain in words20 ptsNot answered

In one or two sentences, explain why the best validation score found by a large hyperparameter search overstates how the model will do on new data.

Math modeKeyboard or LaTeX inputTask 1 of 8 · Ctrl ⏎ to check

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