This is a generic predict() function works for explainer objects.

# S3 method for explainer
predict(object, newdata, ...)

model_prediction(explainer, new_data, ...)

Arguments

object

a model to be explained, object of the class explainer

newdata

data.frame or matrix - observations for prediction

...

other parameters that will be passed to the predict function

explainer

a model to be explained, object of the class explainer

new_data

data.frame or matrix - observations for prediction

Value

An numeric matrix of predictions

Examples

HR_glm_model <- glm(status == "fired"~., data = HR, family = "binomial")
explainer_glm <- explain(HR_glm_model, data = HR)
#> Preparation of a new explainer is initiated
#>   -> model label       :  lm  (  default  )
#>   -> data              :  7847  rows  6  cols 
#>   -> target variable   :  not specified! (  WARNING  )
#>   -> 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.3 , task classification (  default  ) 
#>   -> model_info        :  Model info detected classification task but 'y' is a NULL .  (  WARNING  )
#>   -> model_info        :  By deafult classification tasks supports only numercical 'y' parameter. 
#>   -> model_info        :  Consider changing to numerical vector with 0 and 1 values.
#>   -> model_info        :  Otherwise I will not be able to calculate residuals or loss function.
#>   -> predicted values  :  numerical, min =  0.00861694 , mean =  0.3638333 , max =  0.7822214  
#>   -> residual function :  difference between y and yhat (  default  )
#>   A new explainer has been created!  
predict(explainer_glm, HR[1:3,])
#>         1         2         3 
#> 0.5139357 0.7384469 0.6412859 

 # \donttest{
library("ranger")
HR_ranger_model <- ranger(status~., data = HR, num.trees = 50, probability = TRUE)
explainer_ranger  <- explain(HR_ranger_model, data = HR)
#> Preparation of a new explainer is initiated
#>   -> model label       :  ranger  (  default  )
#>   -> data              :  7847  rows  6  cols 
#>   -> target variable   :  not specified! (  WARNING  )
#>   -> predict function  :  yhat.ranger  will be used (  default  )
#>   -> predicted values  :  No value for predict function target column. (  default  )
#>   -> model_info        :  package ranger , ver. 0.14.1 , task multiclass (  default  ) 
#>   -> model_info        :  Model info detected multiclass task but 'y' is a NULL .  (  WARNING  )
#>   -> model_info        :  By deafult multiclass tasks supports only factor 'y' parameter. 
#>   -> model_info        :  Consider changing to a factor vector with true class names.
#>   -> model_info        :  Otherwise I will not be able to calculate residuals or loss function.
#>   -> predicted values  :  predict function returns multiple columns:  3  (  default  ) 
#>   -> residual function :  difference between 1 and probability of true class (  default  )
#>   A new explainer has been created!  
predict(explainer_ranger, HR[1:3,])
#>          fired         ok    promoted
#> [1,] 0.7342474 0.25886552 0.006887055
#> [2,] 0.9585492 0.03760901 0.003841755
#> [3,] 0.9810689 0.01742826 0.001502793

model_prediction(explainer_ranger, HR[1:3,])
#>          fired         ok    promoted
#> [1,] 0.7342474 0.25886552 0.006887055
#> [2,] 0.9585492 0.03760901 0.003841755
#> [3,] 0.9810689 0.01742826 0.001502793
 # }