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

Feature importance and permutation

Skill positionModule 4 of 4 · Topic 3 of 4
4.3 Feature importance and permutation
—Lab score— / 100Total XP—Streak—

Which feature did the model use

After fitting, you want to know which features the model relies on, to check it makes sense and to drop dead weight. Tree models report an impurity importance: the total split gain each feature produced, divided by the sum over features. It is free to compute but biased toward features with many distinct values, and it is measured on training data, so a noise feature can look important. Permutation importance is more honest. Take a fitted model and a held-out set, shuffle one feature's values, which breaks its link with the target, and record how much the score drops: importancej=sbase−sshuffled,j\text{importance}_j=s_{\text{base}}-s_{\text{shuffled},j}importancej​=sbase​−sshuffled,j​. Repeat the shuffle several times and average.

Ij=s0−1R∑r=1Rsj(r),g~j=gj∑kgkI_j=s_{0}-\frac1R\sum_{r=1}^{R}s_{j}^{(r)},\qquad \tilde g_j=\frac{g_j}{\sum_k g_k}Ij​=s0​−R1​r=1∑R​sj(r)​,g~​j​=∑k​gk​gj​​(1)

Two cautions. First, correlated features share credit: if two columns carry the same information, shuffling one leaves the other to do the work, and both look unimportant. Group such features or drop one. Second, importance describes the model, not the world. A feature that matters to a bad model does not make it a cause of returns. With cross-sectional data, shuffle the feature within each month, so the shuffle keeps the month's level and only breaks the ranking among stocks. Report the spread over the repeats as well, because a small importance with a larger spread is noise.

Five shuffles and the real modelA model scores 0.800.800.80. After shuffling one feature five times, the scores are 0.62,0.66,0.64,0.65,0.680.62,0.66,0.64,0.65,0.680.62,0.66,0.64,0.65,0.68, with mean 0.650.650.65 and standard deviation 0.0220.0220.022, so the importance is 0.80−0.65=0.150.80-0.65=0.150.80−0.65=0.15. If a tree's splits gave gains 0.163,0.05,0.020.163,0.05,0.020.163,0.05,0.02, the impurity shares are 0.70,0.21,0.090.70,0.21,0.090.70,0.21,0.09. Two identical copies of a feature would each show an importance of about 000, because the other copy fills in. On the real monthly stock panel with the ridge model, the walk-forward information coefficient is 0.03270.03270.0327. Shuffling volatility within each month drops it to about 000 (an importance of 0.0330.0330.033), shuffling momentum changes it by −0.003-0.003−0.003 and shuffling last month's return by −0.003-0.003−0.003. The whole signal of this model is the volatility feature.
  • Shuffle and score: importance is how much the held-out score falls when one feature is shuffled.
  • Correlated twins hide each other: group them or drop one before you read the numbers.
  • Importance is about the model: it is a check, not proof that a feature causes returns.

Lab · what's graded

  • The mean of the shuffles10 pts
  • The permutation importance15 pts
  • The spread of the repeats15 pts
  • An impurity share10 pts
  • A twin feature10 pts
  • Which importance to trust10 pts
  • The permutation procedure10 pts
  • Important to the model, not to returns20 pts
0/ 8 answered
Tasks
1Numeric answer10 ptsNot answered

After shuffling one feature five times the scores are 0.62,0.66,0.64,0.65,0.680.62,0.66,0.64,0.65,0.680.62,0.66,0.64,0.65,0.68. What is their mean? Give two decimals.

m=m =m=accepted: ± 0.005
2Numeric answer15 ptsNot answered

The baseline score is 0.800.800.80 and the mean shuffled score is 0.650.650.65. What is the importance sbase−sshuffleds_{\text{base}}-s_{\text{shuffled}}sbase​−sshuffled​? Give two decimals.

i=i =i=accepted: ± 0.005
3Numeric answer15 ptsNot answered

The five shuffled scores 0.62,0.66,0.64,0.65,0.680.62,0.66,0.64,0.65,0.680.62,0.66,0.64,0.65,0.68 have squared deviations from 0.650.650.65 of 0.0009,0.0001,0.0001,0,0.00090.0009,0.0001,0.0001,0,0.00090.0009,0.0001,0.0001,0,0.0009. What is their sample standard deviation (divide by 444)? Give three decimals.

s=s =s=accepted: ± 0.002
4Numeric answer10 ptsNot answered

A tree's splits gave total gains 0.1630.1630.163, 0.050.050.05 and 0.020.020.02 to three features, which sum to 0.2330.2330.233. What is the impurity importance of the first feature, as a fraction? Give two decimals.

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

A feature appears twice in the data as two identical columns. The model scores 0.800.800.80 and scores 0.800.800.80 again after shuffling only one of the copies. What is the permutation importance of that copy?

t=t =t=accepted: ± 0.005
6Choice10 ptsNot answered

A random forest shows a noise feature with many distinct values as important by impurity, but its permutation importance on held-out data is zero. Which do you trust?

7Order the steps10 ptsNot answered

Put the steps of permutation importance 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 again and record the drop from the baseline
  2. 2Score the fitted model on held-out data as the baseline
  3. 3Repeat several times and average the drops
  4. 4Shuffle the values of one feature in the held-out data
8Explain in words20 ptsNot answered

Shuffling the volatility feature drops the model's information coefficient from 0.0330.0330.033 to about 000. In one or two sentences, explain why this does not prove that volatility causes higher returns.

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