# \donttest{
if (requireNamespace("xgboost", quietly = TRUE) &&
requireNamespace("ggplot2", quietly = TRUE) &&
requireNamespace("torch", quietly = TRUE) &&
torch::torch_is_installed()) {
data("airquality")
data <- data.table::as.data.table(airquality)
data <- data[complete.cases(data), ]
x_var <- c("Solar.R", "Wind", "Temp", "Month")
y_var <- "Ozone"
ind_x_explain <- 1:6
x_train <- data[-ind_x_explain, ..x_var]
y_train <- data[-ind_x_explain, get(y_var)]
x_explain <- data[ind_x_explain, ..x_var]
# Fitting a basic xgboost model to the training data
model <- xgboost::xgboost(
data = as.matrix(x_train),
label = y_train,
nround = 100,
verbose = FALSE
)
explanation <- shapr::explain(
model = model,
x_explain = x_explain,
x_train = x_train,
approach = "vaeac",
phi0 = mean(y_train),
n_MC_samples = 1,
vaeac.epochs = 10,
vaeac.n_vaeacs_initialize = 1
)
# Plot the results
figure <- shapr::plot_vaeac_imputed_ggpairs(
explanation = explanation,
which_vaeac_model = "best",
x_true = x_train,
add_title = TRUE
)
figure
# Note that this is an ggplot2 object which we can alter, e.g., we can change the colors.
figure +
ggplot2::scale_color_manual(values = c("#E69F00", "#999999")) +
ggplot2::scale_fill_manual(values = c("#E69F00", "#999999"))
}
# }
Run the code above in your browser using DataLab