σμ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 1 · The estimator way of working›Topic 1.5·~50 minIntermediate

Leak-proof pipelines

Skill positionModule 1 of 4 · Topic 5 of 5
1.5 Leak-proof pipelines
—Lab score— / 100Total XP—Streak—

The quiet leak

Leakage means that information from the test rows reaches the model before it is scored. The loud forms are easy to avoid (a feature built from tomorrow's price). The quiet form hides in preprocessing: you pick the best columns, or scale the data, or fill gaps, using all the rows, and only then split for cross-validation. Every test fold has already influenced the choice, and the score is flattering. Feature selection is the worst offender, because a hundred noisy columns always contain a few that look predictive in any sample; if you choose them on all the data, the test folds are partly 'predicted' by columns that were picked because they fitted those very folds. The structural fix is a Pipeline: when you give cross_val_score the whole pipeline, it refits scaling, selection and the model on each training window and only then scores the test window.

The lab uses a deliberately hard question: can yesterday's returns of 60 other assets predict whether SPY rises today? There is almost nothing to find. The leaky evaluation (SelectKBest(f_classif, k=5) on all rows, then TimeSeriesSplit cross-validation) reports an AUC of 0.534. The honest one (scaler, selector and logistic regression in one pipeline, refitted on each window) reports 0.512. The 0.022 in between is pure leak. You can also look inside: cross_validate(model, X, y, cv=..., return_estimator=True) returns the fitted pipelines, and estimator.named_steps['select'].get_support(indices=True) lists the columns each one chose. Across the five folds only one column is chosen every time, which is what noise selection looks like. A score you computed with a pipeline you can defend; a score computed after 'a little preprocessing on everything' you cannot.

  • Split first, then learn anything: scaling, selection and imputation all belong inside the cross-validation loop.
  • A Pipeline is a leak guard: give cross_val_score the whole pipeline and every step is refitted on each training window.
  • Look at what each fold chose: columns that change from fold to fold are noise, not signal.

Lab · what's graded

  • The leaky evaluation15 pts
  • The pipeline10 pts
  • The honest evaluation15 pts
  • What each fold chose20 pts
  • The size of the leak10 pts
  • The real-data comparison30 pts
Explorer · lab-sl-15
▾ lab-sl-15
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-sl-15$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-sl-15 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