shap_var: SHAP-based dependence plots for categorical/numerical...

Description Usage Arguments Value See Also Examples

View source: R/shapley.R

Description

Having a h2o_shap object, plot a dependence plot for any categorical or numerical feature.

Usage

1
shap_var(x, var, keep_outliers = FALSE)

Arguments

x

h2o_shap object

var

Variable name

keep_outliers

Boolean. Outliers detected with z-score and 3sd may be suppress or kept in your plot. Keep them?

Value

ggplot2 objct with shap values plotted

See Also

Other SHAP: h2o_shap()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## Not run: 
# Train a h2o_automl model
model <- h2o_automl(dft, Survived, max_models = 1, target = TRUE,
                    ignore = c("Ticket", "Cabin", "PassengerId"),
                    quiet = TRUE)

# Calculate SHAP values
SHAP_values <- h2o_shap(model)
# Equivalent to:
# SHAP_values <- h2o_shap(
#  model = model$model,
#  test = model$datasets$test,
#  scores = model$scores_test$scores)

# Check SHAP results
head(SHAP_values)

# You must have "ggbeeswarm" library to use this auxiliary function:
# Plot SHAP values (feature importance)
plot(SHAP_values)

# Plot some of the variables (categorical)
shap_var(SHAP_values, Pclass)

# Plot some of the variables (numerical)
shap_var(SHAP_values, Fare)

## End(Not run)

lares documentation built on June 9, 2021, 9:06 a.m.