A forest that ranks a user id as its top feature
RolesAI Data SystemsAI Evaluation and ReliabilityLLM Product Engineering
The question
A random forest's feature importance puts a user id column near the top of the list. The column is an integer with a different value in almost every row. The team wants to build a product rule around it. What do you tell them, and how do you check?
Answer it first, aloud or on paper. Then open the answer.
The answer
Show short answer
The default importance is the mean decrease in impurity, summed over every split that used the feature. A column that is distinct on nearly every row offers a huge number of candidate thresholds, so trees split on it to carve out small pure groups by chance, and those impurity drops add up on the training data. Run a permutation importance check instead: shuffle the column on held-out data, measure the drop in accuracy, and expect close to zero for an id.
Show full answer
What the default number measures
importance(feature) = sum over nodes that split on it of
(samples at node / total samples) * impurity decreaseThe number is a by-product of training, so it costs nothing, and it is biased in two ways the lesson names: toward features with many distinct values, and toward features with many possible split points. An id column is the extreme case of both. Each tree can find a threshold that isolates a handful of rows with the same label, the gain looks real on the bootstrap sample, and nothing in the formula asks whether it transfers.
The check that does ask
The permutation method shuffles one feature's values on data the model did not train on and measures how much the score drops. A feature the model needs produces a large drop. A feature that only absorbed training noise produces none. It costs one evaluation per feature per repeat, which is slower than the default, but it answers the question the team is asking. The lesson sets this exact case as an exercise: a high cardinality noise feature that the impurity method ranks high and the permutation method does not.
What to tell the team
- The ranking they saw does not mean the id predicts anything.
- Run the permutation check on a validation set with several shuffles and average.
- Retrain without the id and compare validation scores. If the score holds, the id carried nothing.
- If the permutation check also scores the id high, treat it as leakage: ids that correlate with the target through time or data source will not hold in production, and no product rule should rest on them.
Follow-ups
L3SeniorWhy do many distinct values make it easy for a tree to find a good-looking split?
Show expected answer
more thresholds mean more chances that one of them separates a few rows by luck; the gain is real on the training sample and absent on new data.
L3SeniorPermutation importance for the id is near zero and the validation score is fine. What does that say?
Show expected answer
the id carried no signal the model depends on; it absorbed training noise, and the other features do the work.
L4StaffThe permutation importance of the id is large as well. What now?
Show expected answer
suspect leakage; the id tracks the target through time or source, and that link breaks in production.
L4StaffHow do you compute permutation importance so it is not optimistic?
Show expected answer
on held-out data, shuffle only the one column, repeat several times and average, and keep every other column fixed.
Wrong answers
Show the wrong answers that interviewers hear
“The forest found the id useful, so it is useful.”
The impurity sum counts splits that fit training noise; a column with many distinct values collects them.
“Drop every integer column to be safe.”
Integers such as counts carry real signal. Test the one column with a permutation.
“The two importance methods always agree.”
The lesson's exercise builds a case where the impurity method ranks a noise feature highly and the permutation method does not.
Taught in
The decision trees lesson defines both importance measures and names the bias of the impurity method.