This function is set deprecated. It is suggested to use break_down instead. Find information how to use these functions here: https://pbiecek.github.io/PM_VEE/breakDown.html.

prediction_breakdown(explainer, observation, ...)

Arguments

explainer

a model to be explained, preprocessed by the 'explain' function

observation

a new observarvation for which predictions need to be explained

...

other parameters that will be passed to breakDown::broken.default()

Value

An object of the class 'single_prediction_explainer'. It's a data frame with calculated average response.

References

Predictive Models: Visual Exploration, Explanation and Debugging https://pbiecek.github.io/PM_VEE/

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) head(wine_lm_predict4)
#> variable contribution variable_name #> 1 (Intercept) 5.87790935 Intercept #> alcohol + alcohol = 12.5 0.70174103 alcohol #> pH + pH = 3.36 0.05780936 pH #> sulphates + sulphates = 0.6 0.04865885 sulphates #> citric.acid + citric.acid = 0.35 0.00000000 citric.acid #> residual.sugar + residual.sugar = 4.8 -0.03789283 residual.sugar #> variable_value cummulative sign position label #> 1 1 5.877909 1 1 model_4v #> alcohol 12.5 6.579650 1 2 model_4v #> pH 3.36 6.637460 1 3 model_4v #> sulphates 0.6 6.686119 1 4 model_4v #> citric.acid 0.35 6.686119 0 5 model_4v #> residual.sugar 4.8 6.648226 -1 6 model_4v
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) head(wine_rf_predict4)
#> variable contribution variable_name #> 1 (Intercept) 5.8816897 Intercept #> alcohol + alcohol = 12.5 0.5922455 alcohol #> sulphates + sulphates = 0.6 0.1925095 sulphates #> residual.sugar + residual.sugar = 4.8 0.2666629 residual.sugar #> pH + pH = 3.36 0.2781199 pH #> citric.acid + citric.acid = 0.35 0.0000000 citric.acid #> variable_value cummulative sign position label #> 1 1 5.881690 1 1 model_rf #> alcohol 12.5 6.473935 1 2 model_rf #> sulphates 0.6 6.666445 1 3 model_rf #> residual.sugar 4.8 6.933108 1 4 model_rf #> pH 3.36 7.211227 1 5 model_rf #> citric.acid 0.35 7.211227 0 6 model_rf
plot(wine_rf_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.87805095 Intercept #> alcohol + alcohol = 12.5 0.65003490 alcohol #> pH + pH = 3.36 0.15837667 pH #> sulphates + sulphates = 0.6 0.13939640 sulphates #> residual.sugar + residual.sugar = 4.8 0.04042056 residual.sugar #> citric.acid + citric.acid = 0.35 0.00000000 citric.acid #> variable_value cummulative sign position label #> 1 1 5.878051 1 1 gbm #> alcohol 12.5 6.528086 1 2 gbm #> pH 3.36 6.686463 1 3 gbm #> sulphates 0.6 6.825859 1 4 gbm #> residual.sugar 4.8 6.866279 1 5 gbm #> citric.acid 0.35 6.866279 0 6 gbm
plot(exp_sgn)
exp_sgn <- prediction_breakdown(explainer_gbm, observation = new.wine, baseline = 0) plot(exp_sgn)