DALEX (version 0.4.9)

plot.prediction_breakdown_explainer: Plot Break Down Explanations (Single Prediction)

Description

Function plot.single_prediction_explainer plots break down plots for a single prediction.

Usage

# S3 method for prediction_breakdown_explainer
plot(x, ...,
  add_contributions = TRUE, vcolors = c(`-1` = "#f05a71", `0` =
  "#371ea3", `1` = "#8bdcbe", X = "#371ea3"), digits = 3,
  rounding_function = round)

Arguments

x

a single prediction exlainer produced with the single_prediction function

...

other explainers that shall be plotted together

add_contributions

shall variable contributions to be added on plot?

vcolors

named vector with colors

digits

number of decimal places round or significant digits signif to be used. See the rounding_function argument

rounding_function

function that is to used for rounding numbers. It may be signif() which keeps a specified number of significant digits. Or the default round() to have the same precision for all components

Value

a ggplot2 object

Examples

Run this code
# NOT RUN {
 
# }
# NOT RUN {
new_dragon <- data.frame(year_of_birth = 200,
     height = 80,
     weight = 12.5,
     scars = 0,
     number_of_lost_teeth  = 5)

dragon_lm_model4 <- lm(life_length ~ year_of_birth + height +
                                     weight + scars + number_of_lost_teeth,
                       data = dragons)
dragon_lm_explainer4 <- explain(dragon_lm_model4, data = dragons, y = dragons$year_of_birth,
                                label = "model_4v")
dragon_lm_predict4 <- prediction_breakdown(dragon_lm_explainer4, observation = new_dragon)
plot(dragon_lm_predict4)

library("randomForest")
dragon_rf_model4 <- randomForest(life_length ~ year_of_birth + height + weight +
                                               scars + number_of_lost_teeth,
                                 data = dragons)
dragon_rf_explainer4 <- explain(dragon_rf_model4, data = dragons, y = dragons$year_of_birth,
                                label = "model_rf")
dragon_rf_predict4 <- prediction_breakdown(dragon_rf_explainer4, observation = new_dragon)
plot(dragon_rf_predict4)

# both models
plot(dragon_rf_predict4, dragon_lm_predict4)

library("gbm")
# create a gbm model
model <- gbm(life_length ~ year_of_birth + height + weight + scars + number_of_lost_teeth,
             data = dragons,
             distribution = "gaussian",
             n.trees = 1000,
             interaction.depth = 4,
             shrinkage = 0.01,
             n.minobsinnode = 10,
             verbose = FALSE)
 # make an explainer for the model
 explainer_gbm <- explain(model, data = dragons, predict_function =
         function(model, x) predict(model, x, n.trees = 1000))
 # create a new observation
 exp_sgn <- prediction_breakdown(explainer_gbm, observation = new_dragon)
 head(exp_sgn)
 plot(exp_sgn)

 exp_sgn <- prediction_breakdown(explainer_gbm, observation = new_dragon, baseline = 0)
 plot(exp_sgn)
 
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab