Winning Kaggle the Reproducible Way

Chapter 27

SHAP as a Feature Engineering Signal

Use attribution to form a hypothesis, then test the removal on the same development rows.

A near-zero attribution does not make a column unneeded. One demonstration attributes a model's predictions to two near-copies of one signal, then removes the low-attribution copy, then both, and measures the loss each time.

Every example is constructed for teaching. Its numbers come from running the chapter activity's code, not from a competition result.

Demonstration 1 of 1

Low attribution for a copy, and what removing it costs

When two columns carry the same information, does the one with low attribution deserve to be dropped, and what does dropping both cost?

Shapley attribution divides credit among the columns the fitted model used. With identical columns a tree picks one of them at every split (here the first column), so the other receives exactly zero credit and ranks below pure noise. With near-copies the model uses both and the split between them is arbitrary, changing from dataset to dataset. In every case the pair is what the model needs: removing only the low-attribution copy is nearly free when the copies are tight, removing both is expensive.

Equation: phi j equals the sum over subsets S of the other features of the weight |S| factorial times |F| minus |S| minus 1 factorial over |F| factorial, times v of S with j minus v of S

Scroll sideways for the whole equation

phi_j is the attribution of column j to one prediction, v(S) the mean model output when only the columns in S are taken from the explained row, and mean |phi_j| the quantity a SHAP screen ranks. The weight is the share of column orderings in which the columns of S come before j.

Predict first. With two identical columns, what mean absolute attribution does the low-attribution copy receive, and what does dropping both cost?

Your prediction

Choose an example

Scroll sideways for the whole figure

Figure: Low attribution for a copy, and what removing it costs. Left: paired bars of the two copies' mean absolute attribution in eight constructed datasets at copy correlation 1.0, with a dashed line at the noise column level 0.020. Right: log loss added on fresh rows by dropping a noise column (0.000), the low-attribution copy (0.000) and both copies (+0.206).
Correlation between the two copies (1.0 = identical columns): 1.0: identical copy
Constructed example: eight seeded synthetic datasets, a histogram gradient boosting model and exact Shapley enumeration, measured by the chapter activity.

Calculated values

Higher copy |attribution|
0.265
Lower copy |attribution|
0.000
Noise column |attribution|
0.020
Drop low copy
0.000
Drop both copies
+0.206
Drop a noise column
0.000

At copy correlation 1.0: the higher-ranked copy has mean |attribution| 0.265 and the lower-ranked copy 0.000, against 0.020 for a noise column. The low copy ranks below a pure-noise column, so a screen would call it noise. Removing the low copy changes fresh-row log loss by 0.000; removing both copies changes it by +0.206, and 0.206 - 0.000 = 0.206 is the extra cost of dropping the pair. The lower-ranked copy was column A in 0 of 8 datasets.

Worked steps

  1. Share of the pair's attribution held by the low copy: 0.000 / (0.000 + 0.265) = 0.000.
  2. Cost of dropping the low copy: 0.000 log loss; a noise column: 0.000.
  3. Cost of dropping both: 0.206 - 0.000 = 0.206 beyond the single removal.
  4. Low copy was column A in 0 of 8 datasets (column order, not information, breaks a tie).

Use the idea

Treat a low mean |SHAP| as a candidate for a removal experiment, not a verdict. Check correlated substitutes first, remove the candidate and its substitutes as a group on the same development rows, and keep a pure-noise column as the control for what removal costs when a column carries nothing.

Where the conclusion applies

Constructed data. The shap library is not installed, so attribution is computed by exact interventional Shapley enumeration on predicted probability (the chapter's tree explainer is the efficient version of the same idea, and its output is a margin by default), with a histogram gradient boosting classifier standing in for LightGBM. Which of two identical columns receives the credit is decided by column order in this model; other libraries break ties differently.

Check your understanding: Why does the low-attribution copy cost nothing to drop at correlation 1.0, but cost something at correlation 0.5?
At 1.0 the copy repeats what the other column already says, so the refitted model loses nothing (0.000). At 0.5 the two readings carry independent noise, so each one corrects the other, and dropping the low copy costs 0.037 on fresh rows. In both cases dropping both is the expensive step, so a removal test has to be run on the pair.

Chapter 27 source: section "A Removal Contrast".