TreeSHAP and its two games: path-dependent and interventional
TreeSHAP computes exact Shapley values for tree ensembles in polynomial time by walking the trees. Learn the two value functions it can use, why they disagree under correlation, and how to aggregate local values honestly.
What runs in CodeSplash
- EXP003TreeSHAP Runs in CodeSplash (Experimental)
- SHAP values for a saved model Experimental
You will be able to
- Explain how tree structure makes exact Shapley values cheap
- Contrast path-dependent and interventional TreeSHAP value functions
- Check additivity and aggregate local values without losing sign and heterogeneity
Exact, and fast, for trees
ReadKernelSHAP treats the model as a black box and samples subsets. A tree ensemble isn't a black box: each prediction follows paths of splits. TreeSHAPTreeSHAPExact Shapley values for tree ensembles, computed from their structure at little cost. uses that structure to compute exact Shapley values by tracking, along each path, how much of the prediction each feature's splits are responsible for, in time polynomial in the tree depth instead of exponential in the number of features.
For boosted trees on a classification task, the values add up on the log-odds scale, not the probability scale.
Reference · EXP003 · Runs in CodeSplashTreeSHAPCompute Shapley attributions efficiently by using tree structure rather than treating every prediction as an opaque black-box query.Two value functions
Read"Exact" depends on the game. TreeSHAP comes in two versions:
- Path-dependent. An absent feature follows each split in proportion to how many training rows went each way (the tree's stored cover). No background data is needed.
- InterventionalInterventional TreeSHAPTreeSHAP that fills missing features from a background sample; the path-dependent version uses the tree's own training-row splits.. An absent feature takes its values from a background sample, breaking its link with the present features.
With independent features they agree. With correlated features they can rank features differently: the path-dependent version lets a feature's correlate "stand in" through the training splits; the interventional version doesn't. Neither is a causal model.
By hand: a two-feature tree
ReadThe reference's example uses a tiny tree, when both features exceed 0.5, when only the first does, else , with a four-row background and the row . Using background averages as the value function (the interventional game), the base value is 2.50 and the two Shapley values are 1.75 and 0.75: they add up to the prediction, 5. Checking a few tiny trees against full enumeration like this is the standard unit test for any TreeSHAP implementation.
TreeSHAP in CodeSplash
ReadSHAP values for a saved model uses the boosters' own TreeSHAP for XGBoost and LightGBM, the path-dependent version, on the log-odds scale.
Across 40 rows, flipper_len moves the model's log-odds of P(Gentoo) the most (mean |SHAP| 1.84).
- Mean |SHAP|, flipper_len
- 1.842
- Average log-odds of P(Gentoo)
- 0.0423
Plots
View data
| Feature | Mean |SHAP| |
|---|---|
| flipper_len | 1.842 |
| island | 0.4933 |
| bill_dep | 0.2652 |
| body_mass | 0.0419 |
| bill_len | 0 |
| sex | 0 |
View data
| Feature | SHAP (log-odds) | Feature value (scaled) |
|---|---|---|
| flipper_len | −1.567 | 0.1200 |
| flipper_len | −1.521 | 0 |
| flipper_len | −2.109 | 0 |
| flipper_len | −2.109 | 0.1800 |
| flipper_len | −1.373 | 0.1600 |
| flipper_len | −1.373 | 0.2200 |
| flipper_len | −2.109 | 0.1200 |
| flipper_len | −2.109 | 0.4000 |
| flipper_len | −2.109 | 0.1200 |
| flipper_len | −2.304 | 0.3000 |
| flipper_len | −1.373 | 0.2600 |
| flipper_len | −1.373 | 0.1200 |
| flipper_len | −2.109 | 0.2600 |
| flipper_len | −2.109 | 0.0800 |
| flipper_len | −2.109 | 0.2600 |
| flipper_len | −1.373 | 0.3000 |
| flipper_len | −1.373 | 0.3400 |
| flipper_len | −1.567 | 0.2600 |
| flipper_len | −1.567 | 0.2000 |
| flipper_len | 2.203 | 0.5800 |
| flipper_len | 2.097 | 0.9000 |
| flipper_len | 2.097 | 0.6600 |
| flipper_len | 2.097 | 0.9000 |
| flipper_len | 2.203 | 0.6800 |
| flipper_len | 2.097 | 0.6800 |
| flipper_len | 2.097 | 0.8000 |
| flipper_len | 2.097 | 0.8200 |
| flipper_len | 2.398 | 0.8600 |
| flipper_len | 2.373 | 0.8800 |
| flipper_len | 2.097 | 0.5800 |
| flipper_len | 2.097 | 0.7200 |
| flipper_len | 2.373 | 1 |
| flipper_len | 2.097 | 0.7000 |
| flipper_len | −1.373 | 0.4200 |
| flipper_len | −1.373 | 0.3400 |
| flipper_len | −1.373 | 0.0200 |
| flipper_len | −1.373 | 0.3000 |
| flipper_len | −1.373 | 0.4000 |
| flipper_len | −1.373 | 0.3200 |
| flipper_len | −1.373 | 0.4200 |
| island | −0.8177 | 1 |
| island | −0.8177 | 1 |
| island | 0.1713 | 0 |
| island | 0.1713 | 0 |
| island | −0.8177 | 0.5000 |
| island | −0.8177 | 0.5000 |
| island | 0.1713 | 0 |
| island | 0.1713 | 0 |
| island | 0.1713 | 0 |
| island | 0.1713 | 0 |
| island | −0.8177 | 1 |
| island | −0.8177 | 0.5000 |
| island | 0.1713 | 0 |
| island | 0.1713 | 0 |
| island | 0.1713 | 0 |
| island | −0.8177 | 1 |
| island | −0.8177 | 1 |
| island | −0.8177 | 0.5000 |
| island | −0.8177 | 0.5000 |
| island | 0.3149 | 0 |
First 60 of 240 rows.
View data
| SHAP (log-odds) | flipper_len |
|---|---|
| −1.567 | 186 |
| −1.521 | 180 |
| −2.109 | 180 |
| −2.109 | 189 |
| −1.373 | 188 |
| −1.373 | 191 |
| −2.109 | 186 |
| −2.109 | 200 |
| −2.109 | 186 |
| −2.304 | 195 |
| −1.373 | 193 |
| −1.373 | 186 |
| −2.109 | 193 |
| −2.109 | 184 |
| −2.109 | 193 |
| −1.373 | 195 |
| −1.373 | 197 |
| −1.567 | 193 |
| −1.567 | 190 |
| 2.203 | 209 |
| 2.097 | 225 |
| 2.097 | 213 |
| 2.097 | 225 |
| 2.203 | 214 |
| 2.097 | 214 |
| 2.097 | 220 |
| 2.097 | 221 |
| 2.398 | 223 |
| 2.373 | 224 |
| 2.097 | 209 |
| 2.097 | 216 |
| 2.373 | 230 |
| 2.097 | 215 |
| −1.373 | 201 |
| −1.373 | 197 |
| −1.373 | 181 |
| −1.373 | 195 |
| −1.373 | 200 |
| −1.373 | 196 |
| −1.373 | 201 |
View data
| SHAP (log-odds) | Feature | Value |
|---|---|---|
| −1.567 | flipper_len | 186 |
| −0.8177 | island | Torgersen |
| −0.0402 | bill_dep | 17.1 |
| −0.0174 | body_mass | 3300 |
| 0 | bill_len | 37.8 |
| 0 | sex | missing |
Assumptions
- Enough rows — 40 explained rows, 275 background rows.
- Features vary independently — flipper_len and body_mass: |ρ| = 0.85; changing one alone creates unlikely rows, so read their shares as joint.
- Rows resemble the training data — 0.0% of the explained rows fall outside the background's range.
The exact R script · R R version 4.5.1 (2025-06-13)
# SHAP values for a saved model
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method explain.shap 1.1.0 · spec 376abc834635e0a3
# Explains the saved model learn.xgboost/multiclass_penguins with its own learner code (learn.xgboost 1.2.0, driver mode "explain").
# XGBoost
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method learn.xgboost 1.2.0 · spec 5bd576edd347a4f1
# Dataset: ml_penguins (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
suppressPackageStartupMessages(library(xgboost))
# %% Data and split plan
TARGET <- "species"
FEATURES <- c("island", "bill_len", "bill_dep", "flipper_len", "body_mass", "sex")
TASK <- "multiclass"
CLASSES <- c("Adelie", "Chinstrap", "Gentoo")
POSITIVE <- NULL
METRIC <- "log_loss"
SEED <- 42
PARAMS <- list(
n_estimators = 25,
learning_rate = 0.2,
max_depth = 3,
min_child_weight = 1,
subsample = 1,
colsample_bytree = 1,
reg_lambda = 1,
reg_alpha = 0,
gamma = 0,
early_stopping = 0,
validation_fraction = 0.1,
scale_pos_weight = 1,
monotone = "",
max_bin = 256,
threads = 1,
survival_model = "cox",
aft_distribution = "normal",
aft_sigma = 1
)
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ml_penguins.parquet", col_select = unique(c(TARGET, FEATURES))))
plan <- cs_ml_read_plan("model-r/folds.parquet") # host-written folds: identical in Python and R
design <- cs_ml_design(
df, FEATURES,
kinds = list(
island = "categorical",
bill_len = "numeric",
bill_dep = "numeric",
flipper_len = "numeric",
body_mass = "numeric",
sex = "categorical"
),
levels = list(
island = c("Biscoe", "Dream", "Torgersen"),
sex = c("female", "male")
),
impute = "none",
scale = "none",
indicators = FALSE
)
target <- cs_ml_encode_target(df[[TARGET]], TASK, CLASSES, POSITIVE)
y <- target$fit
y_index <- target$index
weights <- cs_ml_class_weights(y_index, TASK, "none", plan$train)
run <- cs_ml_run(TASK, CLASSES, POSITIVE, METRIC)
out <- cs_ml_out_dir("explain-out-r")
warnings <- list()
sample_weights <- function(rows) if (is.null(weights)) NULL else weights[rows + 1L]
rows_of <- function(rows) df[rows + 1L, , drop = FALSE]
# %% Model
# Same parameters as the Python twin: the shared XGBoost core then builds identical trees.
xgb_params <- list(
objective = switch(TASK, regression = "reg:squarederror", binary = "binary:logistic", multiclass = "multi:softprob", survival = "survival:cox"),
eta = PARAMS$learning_rate,
max_depth = as.integer(PARAMS$max_depth),
min_child_weight = PARAMS$min_child_weight,
subsample = PARAMS$subsample,
colsample_bytree = PARAMS$colsample_bytree,
lambda = PARAMS$reg_lambda,
alpha = PARAMS$reg_alpha,
gamma = PARAMS$gamma,
max_bin = as.integer(PARAMS$max_bin),
tree_method = "hist",
nthread = as.integer(PARAMS$threads),
seed = SEED,
eval_metric = switch(TASK, regression = "rmse", binary = "logloss", multiclass = "mlogloss", survival = "cox-nloglik")
)
if (TASK == "multiclass") xgb_params$num_class <- length(CLASSES)
if (TASK == "binary") xgb_params$scale_pos_weight <- PARAMS$scale_pos_weight
# Monotone constraints by design column (numeric and true/false features only).
monotone <- cs_ml_monotone(
PARAMS$monotone,
cs_ml_design_names(list(design = design)),
Filter(function(f) !identical(design$kinds[[f]], "categorical"), FEATURES)
)
warnings <- c(warnings, as.list(monotone$problems))
if (any(monotone$constraints != 0)) {
xgb_params$monotone_constraints <- paste0("(", paste(monotone$constraints, collapse = ","), ")")
}
fit_model <- function(X, y, w) {
rounds <- as.integer(PARAMS$n_estimators)
if (PARAMS$early_stopping > 0 && length(y) > 2) {
# Seeded validation slice of the training rows (same rows in Python).
s <- cs_ml_es_split(length(y), PARAMS$validation_fraction, SEED)
part <- function(idx) xgb.DMatrix(unname(X[idx, , drop = FALSE]), label = y[idx],
weight = if (is.null(w)) NULL else w[idx], missing = NA)
return(xgb.train(params = xgb_params, data = part(s$fit), nrounds = rounds,
evals = list(valid = part(s$valid)),
early_stopping_rounds = as.integer(PARAMS$early_stopping), verbose = 0))
}
dtrain <- xgb.DMatrix(unname(X), label = y, weight = w, missing = NA)
xgb.train(params = xgb_params, data = dtrain, nrounds = rounds, verbose = 0)
}
predict_model <- function(model, X) {
best <- xgb.attr(model, "best_iteration") # set by early stopping (0-based), kept in model.ubj
d <- xgb.DMatrix(unname(X), missing = NA)
p <- if (is.null(best)) predict(model, d) else predict(model, d, iterationrange = c(1L, as.integer(best) + 1L))
if (TASK == "multiclass" && !is.matrix(p)) p <- matrix(p, ncol = length(CLASSES), byrow = TRUE)
p
}
feature_importance <- function(model, names) {
imp <- xgb.importance(model = model) # Gain = share of total gain (features f0, f1, … by position)
idx <- as.integer(sub("^f", "", imp$Feature)) + 1L
stats::setNames(as.list(imp$Gain), names[idx])
}
save_model <- function(model, directory) {
path <- file.path(directory, "model.ubj")
xgb.save(model, path) # loads in Python and R alike
list(list(key = "model", path = path, format = "xgboost-ubj"))
}
load_model <- function(directory) xgb.load(file.path(directory, "model.ubj"))
# %% Explain the model
REQUEST <- jsonlite::fromJSON("{\"analyze\":{\"kind\":\"shap\",\"method\":\"explain.shap\",\"model\":\"learn.xgboost/multiclass_penguins\",\"title\":\"SHAP values for a saved model\",\"version\":\"1.1.0\"},\"class\":\"Gentoo\",\"coalitions\":256,\"kernelBackground\":30,\"kernelRows\":40,\"maxRows\":40,\"methods\":[\"shap\"],\"modelDir\":\"model-r/out\",\"rows\":\"auto\",\"shapRows\":40}", simplifyVector = FALSE)
if (is.null(REQUEST)) REQUEST <- list()
model_dir <- if (is.null(REQUEST$modelDir)) out else REQUEST$modelDir
prep <- cs_ml_design_from_json(paste(readLines(file.path(model_dir, "design.json"), warn = FALSE), collapse = "\n"))
# S3 predict methods (ranger, e1071, …) need their package's namespace loaded.
for (pkg in c("xgboost")) {
suppressWarnings(suppressPackageStartupMessages(requireNamespace(pkg, quietly = TRUE)))
}
model <- load_model(model_dir)
explainer <- cs_ml_explainer(predict_model, model, prep, TASK, CLASSES, POSITIVE, METRIC, cls = REQUEST$class)
rows <- cs_ml_explain_rows(plan, if (is.null(REQUEST$rows)) "auto" else REQUEST$rows,
as.integer(if (is.null(REQUEST$maxRows)) 1000 else REQUEST$maxRows), SEED)
cs_publish(cs_ml_explain(
explainer, df, rows, plan$train, y, y_index, REQUEST, SEED, model_dir, out,
warnings = warnings,
title = "XGBoost",
engine = cs_engine_info("xgboost", "nanoparquet")
))
Across 40 rows, flipper_len moves the model's log-odds of P(Gentoo) the most (mean |SHAP| 1.84).
- Mean |SHAP|, flipper_len
- 1.842
- Average log-odds of P(Gentoo)
- 0.0423
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Enough rows — 40 explained rows, 275 background rows.
- Features vary independently — flipper_len and body_mass: |ρ| = 0.85; changing one alone creates unlikely rows, so read their shares as joint.
- Rows resemble the training data — 0.0% of the explained rows fall outside the background's range.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# SHAP values for a saved model
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method explain.shap 1.1.0 · spec 376abc834635e0a3
# Explains the saved model learn.xgboost/multiclass_penguins with its own learner code (learn.xgboost 1.2.0, driver mode "explain").
# XGBoost
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method learn.xgboost 1.2.0 · spec 5bd576edd347a4f1
# Dataset: ml_penguins (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import os
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash import ml as csml
import xgboost as xgb
from codesplash.ml import boosting as csboost
# %% Data and split plan
TARGET = "species"
FEATURES = ["island", "bill_len", "bill_dep", "flipper_len", "body_mass", "sex"]
TASK = "multiclass"
CLASSES = ["Adelie", "Chinstrap", "Gentoo"]
POSITIVE = None
METRIC = "log_loss"
SEED = 42
PARAMS = {
"n_estimators": 25,
"learning_rate": 0.2,
"max_depth": 3,
"min_child_weight": 1,
"subsample": 1,
"colsample_bytree": 1,
"reg_lambda": 1,
"reg_alpha": 0,
"gamma": 0,
"early_stopping": 0,
"validation_fraction": 0.1,
"scale_pos_weight": 1,
"monotone": "",
"max_bin": 256,
"threads": 1,
"survival_model": "cox",
"aft_distribution": "normal",
"aft_sigma": 1,
}
df = pd.read_parquet("tests/parity/fixtures/ml_penguins.parquet", columns=list(dict.fromkeys([TARGET] + FEATURES)))
plan = csml.read_plan("model-python/folds.parquet") # host-written folds: identical in Python and R
design = csml.Design.for_frame(
df,
FEATURES,
kinds={
"island": "categorical",
"bill_len": "numeric",
"bill_dep": "numeric",
"flipper_len": "numeric",
"body_mass": "numeric",
"sex": "categorical",
},
levels={
"island": ["Biscoe", "Dream", "Torgersen"],
"sex": ["female", "male"],
},
impute="none",
scale="none",
indicators=False,
)
y, y_index = csml.encode_target(df[TARGET], TASK, CLASSES, POSITIVE)
weights = csml.class_weights(y_index, TASK, "none", plan.train)
run = csml.LearnerRun(TASK, CLASSES, POSITIVE, METRIC)
out = csml.out_dir("explain-out-python")
warnings = []
def sample_weights(rows):
return None if weights is None else weights[rows]
# %% Model
# Same parameters as the R twin: the shared XGBoost core then builds identical trees.
XGB_PARAMS = {
"objective": {"regression": "reg:squarederror", "binary": "binary:logistic", "multiclass": "multi:softprob", "survival": "survival:cox"}[TASK],
"eta": PARAMS["learning_rate"],
"max_depth": int(PARAMS["max_depth"]),
"min_child_weight": PARAMS["min_child_weight"],
"subsample": PARAMS["subsample"],
"colsample_bytree": PARAMS["colsample_bytree"],
"lambda": PARAMS["reg_lambda"],
"alpha": PARAMS["reg_alpha"],
"gamma": PARAMS["gamma"],
"max_bin": int(PARAMS["max_bin"]),
"tree_method": "hist",
"nthread": int(PARAMS["threads"]),
"seed": SEED,
"eval_metric": {"regression": "rmse", "binary": "logloss", "multiclass": "mlogloss", "survival": "cox-nloglik"}[TASK],
}
if TASK == "multiclass":
XGB_PARAMS["num_class"] = len(CLASSES)
if TASK == "binary":
XGB_PARAMS["scale_pos_weight"] = PARAMS["scale_pos_weight"]
# Monotone constraints by design column (numeric and true/false features only).
MONOTONE, problems = csboost.monotone_constraints(
PARAMS["monotone"],
csml.FittedDesign(design, {}, {}, {}).names,
[f for f in FEATURES if design.kinds.get(f) != "categorical"],
)
warnings.extend(problems)
if any(MONOTONE):
XGB_PARAMS["monotone_constraints"] = "(" + ",".join(str(c) for c in MONOTONE) + ")"
def fit_model(X, y, w):
rounds = int(PARAMS["n_estimators"])
if PARAMS["early_stopping"] > 0 and len(y) > 2:
# Seeded validation slice of the training rows (same rows in R).
fit, val = csboost.early_stopping_split(len(y), PARAMS["validation_fraction"], SEED)
part = lambda idx: xgb.DMatrix(X[idx], label=y[idx], weight=None if w is None else w[idx], missing=np.nan) # noqa: E731
return xgb.train(
XGB_PARAMS,
part(fit),
num_boost_round=rounds,
evals=[(part(val), "valid")],
early_stopping_rounds=int(PARAMS["early_stopping"]),
verbose_eval=False,
)
return xgb.train(XGB_PARAMS, xgb.DMatrix(X, label=y, weight=w, missing=np.nan), num_boost_round=rounds)
def predict_model(model, X):
best = model.attr("best_iteration") # set by early stopping (0-based), kept in model.ubj
span = (0, int(best) + 1) if best is not None else (0, 0)
return model.predict(xgb.DMatrix(X, missing=np.nan), iteration_range=span)
def feature_importance(model, names):
# Total gain per feature as a share of all gain (= R's xgb.importance()$Gain).
gain = model.get_score(importance_type="total_gain") # keys f0, f1, … (columns by position)
total = sum(gain.values()) or 1.0
return {names[int(k[1:])]: v / total for k, v in gain.items()}
def save_model(model, directory):
path = os.path.join(directory, "model.ubj")
model.save_model(path) # loads in Python and R alike
return [{"key": "model", "path": path, "format": "xgboost-ubj"}]
def load_model(directory):
model = xgb.Booster()
model.load_model(os.path.join(directory, "model.ubj"))
return model
# %% Explain the model
import json
from codesplash.ml import explain as csx
REQUEST = json.loads("{\"analyze\":{\"kind\":\"shap\",\"method\":\"explain.shap\",\"model\":\"learn.xgboost/multiclass_penguins\",\"title\":\"SHAP values for a saved model\",\"version\":\"1.1.0\"},\"class\":\"Gentoo\",\"coalitions\":256,\"kernelBackground\":30,\"kernelRows\":40,\"maxRows\":40,\"methods\":[\"shap\"],\"modelDir\":\"model-python/out\",\"rows\":\"auto\",\"shapRows\":40}") or {}
model_dir = REQUEST.get("modelDir") or out
with open(os.path.join(model_dir, "design.json"), encoding="utf-8") as fh:
prep = csml.FittedDesign.from_json(fh.read())
model = load_model(model_dir)
explainer = csx.Explainer(predict_model, model, prep, TASK, CLASSES, POSITIVE, METRIC, cls=REQUEST.get("class"))
rows = csx.explain_rows(plan, REQUEST.get("rows") or "auto", int(REQUEST.get("maxRows") or 1000), SEED)
cs.publish(
csx.explain(
explainer,
df,
rows,
plan.train,
y,
y_index,
REQUEST,
SEED,
model_dir,
out,
warnings=warnings,
title="XGBoost",
engine=cs.engine_info("xgboost", "numpy", "pandas"),
)
)
For a boosted model of Gentoo penguins, the base value is 0.042 on the log-odds scale, and the most important feature is flipper_len, with a mean absolute value of 1.84. For the interventional game, choose algorithm Kernel with a background sample: an estimate of the same quantity.
Predict: global importance from local values
PredictPredict first
You rank features by the mean absolute TreeSHAP value over all rows. What does the top feature's high mean tell you?
Reveal
Size, not sign or who. The mean of absolute values loses direction and hides heterogeneity: a feature can matter hugely for a few rows and not at all for most. Look at the beeswarm (sign and spread) and at subgroups, and say which rows you averaged over.
Pitfalls
Read- Name the game. Path-dependent and interventional values answer different questions; correlated predictors can swap credit between them.
- Name the scale. Log-odds values don't add up on the probability scale.
- Aggregate deliberately. A global mean of absolute attribution isn't the importance for any one case.
- Explanations aren't evaluations. TreeSHAP describes the fitted model; it is no substitute for held-out performance or fairness checks.
Where it stands in CodeSplash
Read| Entry | In CodeSplash |
|---|---|
| TreeSHAP (EXP003) | Runs in CodeSplash: path-dependent TreeSHAP for XGBoost and LightGBM in SHAP values for a saved model and the Explain tab, Python ≡ R; the interventional game is available as a KernelSHAP estimate with a background sample |
Check your understanding
CheckpointCheck yourself
Why can TreeSHAP compute exact Shapley values quickly when KernelSHAP has to sample?
Show the answer
Answer: b
Tree structure lets the subset sum be computed path by path. The result is exact for the chosen value function.
Check yourself
Two strongly correlated features, A and B. Path-dependent TreeSHAP gives A a large value; interventional TreeSHAP gives B more. Which is wrong?
Show the answer
Answer: c
Report which game you used. When they disagree, group the correlated features or present both views.
Check yourself
A boosted classifier's TreeSHAP values for one row add up to 1.2. What does that number mean?
Show the answer
Answer: b
Boosters' TreeSHAP is additive in margin (log-odds) units. Convert carefully, and don't add log-odds contributions as if they were probabilities.
Recap
Recap- TreeSHAP computes exact Shapley values from tree paths, additive on the model's margin scale.
- Path-dependent (training cover) and interventional (background) games can disagree under correlation.
- Mean absolute values lose sign and heterogeneity; aggregate deliberately.
Concepts in this lesson