shap_long: Every contribution, one row per case per feature

View source: R/explain.R

shap_longR Documentation

Every contribution, one row per case per feature

Description

The long form a beeswarm reads: a point per case per feature, positioned by its contribution and colored by the value the feature took.

Usage

shap_long(x, newdata, class = NULL)

Arguments

x

SHAP object.

newdata

tabular data: The cases x explains.

class

Optional Character: Which class's contributions. NULL takes the first.

Details

Shaped here, for the reason shap_case() gives.

Value

data.table with columns case, feature, value, numeric_value and contribution. numeric_value is NA for a feature that is not numeric, which is what a color scale needs to skip it.

Author(s)

EDG

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)
contributions <- explain(
  mod,
  x[, c("age", "bmi")],
  background = x[, c("age", "bmi")],
  verbosity = 0L
)
head(shap_long(contributions, x[, c("age", "bmi")]))

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.