predict: Predictions for the Explainer

Description Usage Arguments Value Examples

Description

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

Usage

1
2
3
4
## S3 method for class '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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
HR_glm_model <- glm(status == "fired"~., data = HR, family = "binomial")
explainer_glm <- explain(HR_glm_model, data = HR)
predict(explainer_glm, HR[1:3,])

 
library("ranger")
HR_ranger_model <- ranger(status~., data = HR, num.trees = 50, probability = TRUE)
explainer_ranger  <- explain(HR_ranger_model, data = HR)
predict(explainer_ranger, HR[1:3,])

model_prediction(explainer_ranger, HR[1:3,])
 

Example output

Welcome to DALEX (version: 2.0.1).
Find examples and detailed introduction at: https://pbiecek.github.io/ema/

Preparation of a new explainer is initiated
  -> model label       :  lm  ( [33m default [39m )
  -> data              :  7847  rows  6  cols 
  -> target variable   :  not specified! ( [31m WARNING [39m )
  -> predict function  :  yhat.glm  will be used ( [33m default [39m )
  -> predicted values  :  numerical, min =  0.00861694 , mean =  0.3638333 , max =  0.7822214  
  -> model_info        :  package stats , ver. 4.0.3 , task classification ( [33m default [39m ) 
  -> model_info        :  Model info detected classification task but 'y' is a NULL .  ( [31m WARNING [39m )
  -> 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.
  -> residual function :  difference between y and yhat ( [33m default [39m )
 [32m A new explainer has been created! [39m 
        1         2         3 
0.5139357 0.7384469 0.6412859 
Preparation of a new explainer is initiated
  -> model label       :  ranger  ( [33m default [39m )
  -> data              :  7847  rows  6  cols 
  -> target variable   :  not specified! ( [31m WARNING [39m )
  -> predict function  :  yhat.ranger  will be used ( [33m default [39m )
  -> predicted values  :  predict function returns multiple columns:  3  ( [33m default [39m ) 
  -> model_info        :  package ranger , ver. 0.12.1 , task multiclass ( [33m default [39m ) 
  -> model_info        :  Model info detected multiclass task but 'y' is a NULL .  ( [31m WARNING [39m )
  -> model_info        :  By deafult classification 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.
  -> residual function :  difference between 1 and probability of true class ( [33m default [39m )
 [32m A new explainer has been created! [39m 
         fired         ok    promoted
[1,] 0.7255021 0.25893758 0.015560310
[2,] 0.9799241 0.01711289 0.002962978
[3,] 0.9580670 0.04054411 0.001388889
         fired         ok    promoted
[1,] 0.7255021 0.25893758 0.015560310
[2,] 0.9799241 0.01711289 0.002962978
[3,] 0.9580670 0.04054411 0.001388889

DALEX documentation built on July 28, 2021, 5:09 p.m.

Related to predict in DALEX...