@@ -46,8 +46,8 @@ Let's model diamonds prices!
4646### Linear regression
4747
4848``` r
49- library(ggplot2 )
5049library(kernelshap )
50+ library(ggplot2 )
5151library(shapviz )
5252
5353diamonds <- transform(
@@ -221,6 +221,36 @@ shap_gam
221221# [2,] -0.5153642 -0.1080045 0.11967804 0.031341595
222222```
223223
224+ ## Multi-output models
225+
226+ {kernelshap} supports multivariate predictions, such as:
227+ - probabilistic classification,
228+ - non-probabilistic classification (factor-valued responses are turned into dummies),
229+ - regression with multivariate response, and
230+ - predictions found by applying multiple regression models.
231+
232+ ### Classification
233+
234+ We use {ranger} to fit a probabilistic and a non-probabilistic classification model.
235+
236+ ``` r
237+ library(kernelshap )
238+ library(ranger )
239+ library(shapviz )
240+
241+ # Probabilistic
242+ fit_prob <- ranger(Species ~ . , data = iris , num.trees = 20 , probability = TRUE , seed = 1 )
243+ ks_prob <- kernelshap(fit_prob , X = iris , bg_X = iris ) | >
244+ shapviz()
245+ sv_importance(ks_prob )
246+
247+ # Non-probabilistic: Predictions are factors
248+ fit_class <- ranger(Species ~ . , data = iris , num.trees = 20 , seed = 1 )
249+ ks_class <- kernelshap(fit_class , X = iris , bg_X = iris ) | >
250+ shapviz()
251+ sv_importance(ks_class )
252+ ```
253+
224254## Meta-learning packages
225255
226256Here, we provide some working examples for "tidymodels", "caret", and "mlr3".
@@ -283,7 +313,7 @@ fit_lm$train(task_iris)
283313s <- kernelshap(fit_lm , iris [- 1 ], bg_X = iris )
284314s
285315
286- # Probabilistic classification -> lrn(..., predict_type = "prob")
316+ # * Probabilistic* classification -> lrn(..., predict_type = "prob")
287317task_iris <- TaskClassif $ new(id = " class" , backend = iris , target = " Species" )
288318fit_rf <- lrn(" classif.ranger" , predict_type = " prob" , num.trees = 50 )
289319fit_rf $ train(task_iris )
0 commit comments