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.
ranger.unify(rf_model, data)a unified model representation - a model_unified.object object
if (requireNamespace("ranger", quietly = TRUE)) {
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)
}
#>
#> Attaching package: ‘ranger’
#> The following object is masked from ‘package:randomForest’:
#>
#> importance
#>
|0%----|------|20%---|------|40%---|------|60%---|------|80%---|------|100%
#> =---------------------------------------------------------------------- (0%)
====================================----------------------------------- (50%)
======================================================================= (100%)
#> `height` was translated to `width`.