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

# 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

library("breakDown") new.wine <- data.frame(citric.acid = 0.35, sulphates = 0.6, alcohol = 12.5, pH = 3.36, residual.sugar = 4.8) wine_lm_model4 <- lm(quality ~ pH + residual.sugar + sulphates + alcohol, data = wine) wine_lm_explainer4 <- explain(wine_lm_model4, data = wine, label = "model_4v") wine_lm_predict4 <- prediction_breakdown(wine_lm_explainer4, observation = new.wine)
#> Warning: Please note that 'prediction_breakdown()' is now deprecated, it is better to use 'iBreakDown::break_down()' instead. #> Find examples and detailed introduction at: https://pbiecek.github.io/PM_VEE/breakDown.html
plot(wine_lm_predict4)
library("randomForest") wine_rf_model4 <- randomForest(quality ~ pH + residual.sugar + sulphates + alcohol, data = wine) wine_rf_explainer4 <- explain(wine_rf_model4, data = wine, label = "model_rf") wine_rf_predict4 <- prediction_breakdown(wine_rf_explainer4, observation = new.wine) plot(wine_rf_predict4)
# both models plot(wine_rf_predict4, wine_lm_predict4)
library("gbm") # create a gbm model model <- gbm(quality ~ pH + residual.sugar + sulphates + alcohol, data = wine, 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 = wine, predict_function = function(model, x) predict(model, x, n.trees = 1000)) # create a new observation exp_sgn <- prediction_breakdown(explainer_gbm, observation = new.wine) head(exp_sgn)
#> variable contribution variable_name #> 1 (Intercept) 5.87730600 Intercept #> alcohol + alcohol = 12.5 0.64079315 alcohol #> pH + pH = 3.36 0.15945220 pH #> sulphates + sulphates = 0.6 0.12732433 sulphates #> residual.sugar + residual.sugar = 4.8 0.04643455 residual.sugar #> citric.acid + citric.acid = 0.35 0.00000000 citric.acid #> variable_value cummulative sign position label #> 1 1 5.877306 1 1 gbm #> alcohol 12.5 6.518099 1 2 gbm #> pH 3.36 6.677551 1 3 gbm #> sulphates 0.6 6.804876 1 4 gbm #> residual.sugar 4.8 6.851310 1 5 gbm #> citric.acid 0.35 6.851310 0 6 gbm
plot(exp_sgn)
plot(wine_rf_predict4, wine_lm_predict4, exp_sgn)