figure_shap | R Documentation |
Creates SHAP (SHapley Additive exPlanations) plots to explain feature contributions by training a surrogate model on the original model's scores.
figure_shap(data, raw_data, target_type, file = NULL, model_type = "xgboost")
data |
A list containing |
raw_data |
A data frame with original features. The first column must be the sample ID. |
target_type |
String, the analysis type: "diagnosis" or "prognosis".
This determines which columns in |
file |
Optional. A string specifying the path to save the plot. If |
model_type |
String, the surrogate model for SHAP calculation. "xgboost" (default) or "lasso". |
A patchwork object combining SHAP summary and importance plots. If file
is
provided, the plot is also saved.
# --- Example for a Diagnosis Model ---
set.seed(123)
train_dia_data <- data.frame(
SampleID = paste0("S", 1:100),
Label = sample(c(0, 1), 100, replace = TRUE),
FeatureA = rnorm(100, 10, 2),
FeatureB = runif(100, 0, 5)
)
model_results <- list(
sample_score = data.frame(ID = paste0("S", 1:100), score = runif(100, 0, 1))
)
# Generate SHAP plot object
shap_plot <- figure_shap(
data = model_results,
raw_data = train_dia_data,
target_type = "diagnosis",
model_type = "xgboost"
)
# To display the plot:
# print(shap_plot)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.