Learn R Programming

treeshap (version 0.3.1)

ranger.unify: Unify ranger model

Description

Convert your ranger model into a standardized representation. The returned representation is easy to be interpreted by the user and ready to be used as an argument in treeshap() function.

Usage

ranger.unify(rf_model, data)

Value

a unified model representation - a model_unified.object object

Arguments

rf_model

An object of ranger class. At the moment, models built on data with categorical features are not supported - please encode them before training.

data

Reference dataset. A data.frame or matrix with the same columns as in the training set of the model. Usually dataset used to train model.

See Also

lightgbm.unify for LightGBM models

gbm.unify for GBM models

xgboost.unify for XGBoost models

randomForest.unify for randomForest models

Examples

Run this code

 library(ranger)
 data_fifa <- fifa20$data[!colnames(fifa20$data) %in%
                            c('work_rate', 'value_eur', 'gk_diving', 'gk_handling',
                             'gk_kicking', 'gk_reflexes', 'gk_speed', 'gk_positioning')]
 data <- na.omit(cbind(data_fifa, target = fifa20$target))

 rf <- ranger::ranger(target~., data = data, max.depth = 10, num.trees = 10)
 unified_model <- ranger.unify(rf, data)
 shaps <- treeshap(unified_model, data[1:2,])
 plot_contribution(shaps, obs = 1)

Run the code above in your browser using DataLab