Bias, variance, feature importance, and SHAP
Databricks Machine Learning Associate · Lesson 16 of 19 · 2:02:38
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Databricks Certified Machine Learning Associate exam. In this lesson: bias and variance (underfitting and overfitting), feature importance and permutation importance, feature selection, and SHAP values that explain a single prediction. Includes three original practice questions.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Sixty features
The demand model of Juniper Rides now uses sixty features, and its validation error went up as features were added. Operations managers also ask why one station got a forecast twice as high as usual. This lesson covers bias and variance, feature importance, feature selection, and SHAP values.
Bias and variance
The error of a model comes partly from bias, wrong assumptions that make it too simple, and partly from variance, a sensitivity to the particular training data that makes it too complex. A model with high bias underfits: its error is high on the training data and on the validation data, and the two stay close. A model with high variance overfits: it learns the noise of the training data, so it does well there, and much worse on new data. Against underfitting, add useful features, use a more flexible model, like deeper trees, or reduce regularization. Against overfitting, add training data, remove features, limit the depth of trees, strengthen regularization, or stop training early. The goal is the balance point, where the validation error is lowest, and a learning curve, the error against the training size, shows which side a model is on.
Feature importance
Feature importance tells which features a model relies on, overall. Tree based models expose an impurity based importance, like feature importances in scikit-learn, or featureImportances in Spark ML, computed from the training data during the fit. It is fast, but biased toward features with many distinct values, like an ID, and it can rank a feature high even when it does not help on new data. Permutation importance shuffles one feature at a time, on held out data, and measures how much the score drops, which works for any model, and avoids that bias. When two features are strongly correlated, permuting one barely hurts, since the other still carries the information, so both can look unimportant.
Feature selection
Feature selection keeps only the features that help, which simplifies the model, speeds up training and serving, and can reduce overfitting. SelectFromModel, in scikit-learn, keeps the features whose importance in a fitted model is above a threshold, like the mean importance. Other methods remove features with almost no variance, or add and remove features step by step, while watching the validation score. Select features on the training data only, inside the pipeline or the cross-validation, otherwise the choice leaks information from the validation data.
SHAP
SHAP explains individual predictions, with Shapley values from game theory. For one row, each feature gets a SHAP value, its contribution, which pushes the prediction up or down from the base value, the average model output over a background dataset. The base value plus all the SHAP values of a row equals the prediction for that row. A waterfall plot, or a force plot, shows these contributions for one prediction, like why one station got a doubled forecast. Across many rows, a beeswarm plot shows the spread of the SHAP values of each feature, and a bar plot of their mean absolute values gives a global importance. And MLflow can store SHAP plots with a run, as artifacts, next to the model.
Recap
Let's recap. High bias underfits, with high errors on training and validation data, and high variance overfits, doing much worse on new data. More flexibility fights underfitting, while more data, fewer features, and more regularization fight overfitting. Impurity importance is fast, but biased toward features with many values, and permutation importance on held out data avoids that bias. Feature selection, like SelectFromModel, keeps the features that help, chosen on training data only. And SHAP values explain one prediction, from the base value to the prediction, while their mean absolute values give a global importance.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
The demand model has a training RMSE of 40 rides and a validation RMSE of 42, and both are far above what the team needs. What is the likely problem, and the fix?
- High variance: add regularization
- Overfitting: remove features
- High bias: a more flexible model, more features
- Data leakage: fix the split
Show the answer
High bias: a more flexible model, more features
Both errors are high and close, which is underfitting, so the model needs more flexibility, or more useful features. “High variance: add regularization” would make the model even simpler. “Overfitting: remove features” treats it as overfitting, but the two errors are close. And “Data leakage: fix the split” is wrong, since leakage makes a validation score look too good, not too poor.
An impurity-based importance ranks the trip ID first in the damage classifier, though an ID carries no meaning. What gives a more reliable ranking?
- Permutation importance on held-out data
- The same importance, with more trees
- Impurity importance, computed on the test set
- Sorting features by distinct values
Show the answer
Permutation importance on held-out data
Permutation importance measures how much the score drops on held out data when a feature is shuffled, so a meaningless ID falls to the bottom. “The same importance, with more trees” keeps the same bias toward features with many values. “Impurity importance, computed on the test set” is not possible, since impurity importance comes from the fit on the training data. And “Sorting features by distinct values” would put the ID first again.
For one station, the base value is 200 rides and the forecast is 320. A local festival has a SHAP value of +150, and rain has −40. What do all the other features add together?
- +120 rides
- −70 rides
- +110 rides
- +10 rides
Show the answer
+10 rides
The base value plus all the SHAP values gives the prediction, so two hundred, plus 100 and fifty, minus forty, plus ten, makes three hundred and twenty. “+120 rides” is the whole gap, which ignores the festival and the rain. “−70 rides” counts the rain as if it raised the forecast. And “+110 rides” is the sum of the two known values, not what remains.