σμ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 4 · Structure and insight›Topic 4.6·~45 minAdvanced

Joblib caching and saved models

Skill positionModule 4 of 4 · Topic 6 of 7
4.6 Joblib caching and saved models
—Lab score— / 100Total XP—Streak—
Lecture0% read

2 min read

01

Do the work once, and be able to prove it

Research repeats itself: the same grid of settings over the same folds, the same feature table rebuilt for every experiment. joblib removes the waste. Parallel(n_jobs=k)(delayed(f)(x) for x in items) runs the independent calls f(x) on k workers and returns the results in the order of the items; n_jobs=-1 uses every core, and n_jobs=1 runs them one after the other, which is what a browser does. The cost of a job must be larger than the cost of sending its data to a worker, so group tiny jobs together. A grid search is a perfect fit: 5 alphas times 5 walk-forward folds is 25 independent fits, and the answer does not depend on how many workers ran them.

Memory(location).cache(f) wraps f in a disk cache. The first call with some arguments runs f and stores the result under a hash of the arguments; the next call with the same arguments reads the file. The cache survives the end of the program, and it notices when f or an argument changes. Hash NumPy arrays rather than DataFrames: the hash of a DataFrame can depend on its internal memory layout, so two frames with equal content may hash differently, and the cache then misses. joblib.hash(array) is a fingerprint of the content: equal for a copy, different after any change, which is how you prove that two experiments used the same data. Finally joblib.dump(model, path, compress=3) writes a fitted model to a compressed file and joblib.load(path) brings back an object that predicts exactly the same. In the lab, 25 jobs give walk-forward rank correlations within 0.06 of zero at every alpha, slow_features runs once for two cached calls, and the reloaded Ridge predicts identically.

  • Independent jobs go through Parallel and delayed; the answer must not depend on n_jobs.
  • Memory.cache stores results on disk keyed by a hash of the arguments; pass arrays, not frames.
  • joblib.hash proves two runs used the same data; dump and load save a model that predicts identically.

Lab · what's graded

6 tasks · 100 pts
  • One fold job15 pts
  • The grid of jobs25 pts
  • The disk cache15 pts
  • The fingerprint10 pts
  • Saving a model15 pts
  • The study20 pts
Explorer · lab-sl-24
▾ lab-sl-24
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-sl-24$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

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