Explanations for a Single Prediction
single_prediction(explainer, observation, ...)
explainer | a model to be explained, preprocessed by the 'explain' function |
---|---|
observation | a new observarvation for which predictions need to be explained |
... | other parameters |
An object of the class 'single_prediction_explainer'. It's a data frame with calculated average response.
library("randomForest") 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 <- single_prediction(wine_lm_explainer4, observation = new.wine) wine_lm_predict4#> variable contribution variable_name variable_value #> alcohol alcohol = 12.5 0.70174103 alcohol 12.5 #> pH pH = 3.36 0.05780936 pH 3.36 #> sulphates sulphates = 0.6 0.04865885 sulphates 0.6 #> residual.sugar residual.sugar = 4.8 -0.03789283 residual.sugar 4.8 #> 1 final_prognosis 0.77031640 #> cummulative sign position label #> alcohol 0.7017410 1 1 model_4v #> pH 0.7595504 1 2 model_4v #> sulphates 0.8082092 1 3 model_4v #> residual.sugar 0.7703164 -1 4 model_4v #> 1 0.7703164 X 5 model_4vwine_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 <- single_prediction(wine_rf_explainer4, observation = new.wine) wine_rf_predict4#> variable contribution variable_name #> 1 (Intercept) 0.0000000 Intercept #> alcohol + alcohol = 12.5 0.5829462 alcohol #> sulphates + sulphates = 0.6 0.1940118 sulphates #> residual.sugar + residual.sugar = 4.8 0.2466960 residual.sugar #> pH + pH = 3.36 0.2805923 pH #> citric.acid + citric.acid = 0.35 0.0000000 citric.acid #> 11 final_prognosis 1.3042463 #> variable_value cummulative sign position label #> 1 1 0.0000000 0 1 model_rf #> alcohol 12.5 0.5829462 1 2 model_rf #> sulphates 0.6 0.7769580 1 3 model_rf #> residual.sugar 4.8 1.0236540 1 4 model_rf #> pH 3.36 1.3042463 1 5 model_rf #> citric.acid 0.35 1.3042463 0 6 model_rf #> 11 1.3042463 X 7 model_rflibrary("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) # create a new observation exp_sgn <- single_prediction(explainer_gbm, observation = new.wine, n.trees = 1000) exp_sgn#> variable contribution variable_name #> 1 (Intercept) 0.0000000 Intercept #> alcohol + alcohol = 12.5 0.6398519 alcohol #> pH + pH = 3.36 0.1600515 pH #> sulphates + sulphates = 0.6 0.1306007 sulphates #> residual.sugar + residual.sugar = 4.8 0.0406708 residual.sugar #> citric.acid + citric.acid = 0.35 0.0000000 citric.acid #> 11 final_prognosis 0.9711748 #> variable_value cummulative sign position label #> 1 1 0.0000000 0 1 gbm #> alcohol 12.5 0.6398519 1 2 gbm #> pH 3.36 0.7999033 1 3 gbm #> sulphates 0.6 0.9305040 1 4 gbm #> residual.sugar 4.8 0.9711748 1 5 gbm #> citric.acid 0.35 0.9711748 0 6 gbm #> 11 0.9711748 X 7 gbm