Learn R Programming

IBLM (version 1.0.2)

extract_booster_shap: Extract SHAP values from an xgboost Booster model

Description

A function to extract SHAP (SHapley Additive exPlanations) values from fitted booster model

Usage

extract_booster_shap(booster_model, data, ...)

# S3 method for xgb.Booster extract_booster_shap(booster_model, data, ...)

Value

A data frame of SHAP values, where each column corresponds to a feature and each row corresponds to an observation.

Arguments

booster_model

A model object. In the IBLM context it will be the "booster_model" item from an object of class "iblm"

data

A data frame containing the predictor variables. Note anything extra will be quietly dropped.

...

Additional arguments passed to methods.

Methods (by class)

  • extract_booster_shap(xgb.Booster): Extract SHAP values from an `xgb.Booster` model

Details

Currently only a booster_model of class `xgb.Booster` is supported

See Also

[xgboost::predict.xgb.Booster()]

Examples

Run this code
df_list <- freMTPLmini |> split_into_train_validate_test(seed = 9000)

iblm_model <- train_iblm_xgb(
  df_list,
  response_var = "ClaimRate",
  family = "poisson"
)

booster_shap <- extract_booster_shap(iblm_model$booster_model, df_list$test)

booster_shap |> dplyr::glimpse()

Run the code above in your browser using DataLab