One case's contributions, ordered by how much they moved the prediction
Source:R/explain.R
shap_case.RdThe three things a per-case explanation is: where the prediction would have started, what each feature did to it, and where it ended.
Value
List with steps (a data.table of feature, value and
contribution), baseline, predicted, case and class.
Details
Shaped here, following session_timeline(): the
table is the shared input for rtemis.draw's chart and for rtemislive, so both
show the same thing, and it is useful on its own without either.
Features are ordered by the magnitude of their contribution, which is the order a waterfall reads in, and each carries the value it took for this case so the row reads "age = 62, +0.4".
Examples
x <- data.frame(age = rnorm(100), bmi = rnorm(100))
x[["y"]] <- x[["age"]] * 2 + rnorm(100, sd = 0.3)
mod <- train(x, hyperparameters = setup_GLM(), verbosity = 0L)#> Error in UseMethod("train"): no applicable method for 'train' applied to an object of class "data.frame"contributions <- explain(
mod,
x[, c("age", "bmi")],
background = x[, c("age", "bmi")],
verbosity = 0L
)#> Error: object 'mod' not foundshap_case(contributions, x[, c("age", "bmi")], case = 1L)#> Error: object 'contributions' not found