Skip to contents

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.

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.

Details

Shaped here, for the reason shap_case() gives.

Author

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)
#> 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 found
head(shap_long(contributions, x[, c("age", "bmi")]))
#> Error: object 'contributions' not found