6

I'm asked to create a SHAP analysis in R but I cannot find it how to obtain it for a CatBoost model. I can get the SHAP values of an XGBoost model with

shap_values <- shap.values(xgb_model = model, X_train = train_X)

but not for CatBoost.

Here is the reproducible code for my CatBoost model:

library(data.table)
library(catboost)

train_example <- data.table(categorical_feature = c("a", "b", "a", "a", "b"), payment = c(244, 52352, 4235, 3422, 535), age = c(34, 27, 19, 40, 92), target = c(0,0,1,0,1)) label_values_train <- train_example$target train_X <-train_example[, - "target"] train_X$categorical_feature <- as.factor(train_X$categorical_feature)

datapool for the train dataset:

pool <- catboost.load_pool(train_X, label = label_values_train, cat_features = 1) fit_params_report <- list(iterations = 1000, loss_function = 'Logloss', eval_metric='F1', border_count = 42, depth = 8, learning_rate = 0.04, l2_leaf_reg = 0.001, task_type = 'CPU')

model <- catboost.train(pool, params = fit_params_report)

How can I proceed to get the SHAP values here?

Osama Rizwan
  • 201
  • 1
  • 2
  • 7
user100740
  • 91
  • 2

1 Answers1

1
catboost::catboost.get_feature_importance(model, pool = pool, type = "ShapValues")
Stephen Rauch
  • 1,831
  • 11
  • 23
  • 34
JensMB
  • 11
  • 1