Learn R Programming

SHAPforxgboost (version 0.2.0)

shap.plot.force_plot_bygroup: Create faceted SHAP force plots by cluster

Description

Creates a faceted display with one force plot per observation cluster, allowing comparison of prediction patterns across different groups.

Usage

shap.plot.force_plot_bygroup(shapobs, id = "sorted_id", y_parent_limit = NULL)

Arguments

shapobs

The dataset obtained by shap.prep.stack.data.

id

the id variable.

y_parent_limit

set y-axis limits.

Examples

Run this code
# Example: SHAP force plots (stacked bar charts)
# Shows contribution of each feature to individual predictions

plot_data <- shap.prep.stack.data(shap_contrib = shap_values_iris,
                                  n_groups = 4)
shap.plot.force_plot(plot_data)
shap.plot.force_plot(plot_data, zoom_in_group = 2)

# Plot all clusters separately
shap.plot.force_plot_bygroup(plot_data)

Run the code above in your browser using DataLab