This example demonstrates how to use the breakDown package for models created with the caret package.

First we will generate some data.

Now we are ready to train a model. Let’s train a glm model with caret.

To use breakDown we need a function that will calculate scores/predictions for a single observation. By default the predict() function returns predicted class.

So we are adding type = "prob" argument to get scores. And since there will be two scores for each observarion we need to extract one of them.

Now we are ready to call the broken() function.

And plot it.

library(ggplot2)
plot(explain_2) + ggtitle("breakDown plot for caret/glm model")