Prints Individual Variable Explainer Summary

# S3 method for ceteris_paribus_explainer
print(x, ...)

Arguments

x

an individual variable profile explainer produced with the ceteris_paribus() function

...

other arguments that will be passed to head()

Examples

library("DALEX")
library("ingredients")
titanic_small <- select_sample(titanic_imputed, n = 500, seed = 1313)

# build a model
model_titanic_glm <- glm(survived ~ gender + age + fare,
                         data = titanic_small,
                         family = "binomial")

explain_titanic_glm <- explain(model_titanic_glm,
                               data = titanic_small[,-8],
                               y = titanic_small[,8])
#> Preparation of a new explainer is initiated
#>   -> model label       :  lm  (  default  )
#>   -> data              :  500  rows  7  cols 
#>   -> target variable   :  500  values 
#>   -> predict function  :  yhat.glm  will be used (  default  )
#>   -> predicted values  :  No value for predict function target column. (  default  )
#>   -> model_info        :  package stats , ver. 4.2.2 , task classification (  default  ) 
#>   -> predicted values  :  numerical, min =  0.0795294 , mean =  0.302 , max =  0.9859411  
#>   -> residual function :  difference between y and yhat (  default  )
#>   -> residuals         :  numerical, min =  -0.8204691 , mean =  8.796651e-12 , max =  0.8567173  
#>   A new explainer has been created!  

cp_glm <- ceteris_paribus(explain_titanic_glm, titanic_small[1,])
cp_glm
#> Top profiles    : 
#>         gender   age class    embarked fare sibsp parch    _yhat_ _vname_ _ids_
#> 515     female 45.00   2nd Southampton 10.1     0     0 0.5595687  gender   515
#> 515.1     male 45.00   2nd Southampton 10.1     0     0 0.1448038  gender   515
#> 5151      male  0.75   2nd Southampton 10.1     0     0 0.3135247     age   515
#> 515.110   male  2.99   2nd Southampton 10.1     0     0 0.3028164     age   515
#> 515.2     male  4.98   2nd Southampton 10.1     0     0 0.2934793     age   515
#> 515.3     male  7.00   2nd Southampton 10.1     0     0 0.2841757     age   515
#>         _label_
#> 515          lm
#> 515.1        lm
#> 5151         lm
#> 515.110      lm
#> 515.2        lm
#> 515.3        lm
#> 
#> 
#> Top observations:
#>     gender age class    embarked fare sibsp parch    _yhat_ _label_ _ids_
#> 515   male  45   2nd Southampton 10.1     0     0 0.1448038      lm     1

# \donttest{
library("ranger")

apartments_rf_model <- ranger(m2.price ~., data = apartments)

explainer_rf <- explain(apartments_rf_model,
                        data = apartments_test[,-1],
                        y = apartments_test[,1],
                        label = "ranger forest",
                        verbose = FALSE)

apartments_small <- select_sample(apartments_test, 10)

cp_rf <- ceteris_paribus(explainer_rf, apartments_small)
cp_rf
#> Top profiles    : 
#>        construction.year surface floor no.rooms    district   _yhat_
#> 9707                1920      98     3        3 Srodmiescie 4880.584
#> 9707.1              1921      98     3        3 Srodmiescie 4890.136
#> 9707.2              1922      98     3        3 Srodmiescie 4897.864
#> 9707.3              1923      98     3        3 Srodmiescie 4866.403
#> 9707.4              1924      98     3        3 Srodmiescie 4836.051
#> 9707.5              1925      98     3        3 Srodmiescie 4833.932
#>                  _vname_ _ids_       _label_
#> 9707   construction.year  9707 ranger forest
#> 9707.1 construction.year  9707 ranger forest
#> 9707.2 construction.year  9707 ranger forest
#> 9707.3 construction.year  9707 ranger forest
#> 9707.4 construction.year  9707 ranger forest
#> 9707.5 construction.year  9707 ranger forest
#> 
#> 
#> Top observations:
#>      construction.year surface floor no.rooms    district   _yhat_
#> 9707              2008      98     3        3 Srodmiescie 4739.858
#> 9796              1932     110    10        4       Ursus 2922.596
#> 9644              1980      73    10        2     Mokotow 3703.307
#> 7567              1940      63     8        3       Praga 3271.446
#> 4090              1955     105     3        3      Ochota 3594.067
#> 8594              1999      36     9        2       Ursus 3695.560
#>            _label_ _ids_
#> 9707 ranger forest     1
#> 9796 ranger forest     2
#> 9644 ranger forest     3
#> 7567 ranger forest     4
#> 4090 ranger forest     5
#> 8594 ranger forest     6
# }