Skip to content

Instantly share code, notes, and snippets.

@almogsi
Created March 21, 2020 15:04
Show Gist options
  • Select an option

  • Save almogsi/5791894793a391af9d7add7ca67edb08 to your computer and use it in GitHub Desktop.

Select an option

Save almogsi/5791894793a391af9d7add7ca67edb08 to your computer and use it in GitHub Desktop.
Lime with Caret
library(tidyverse)
library(caret)
library(lime)
#fit
lasso_caret<- train(data = mtcars, mpg~., method = "glmnet",
tuneGrid = expand.grid(alpha = 1,
lambda = 0))
#LIME
explainer <- lime(mtcars, lasso_caret) #here the train data
explanation <- explain(mtcars, explainer) #here the test data
#plots
plot_features(explanation, ncol = 2)
plot_features(explanation, ncol = 1, cases = "Volvo 142E") #plot a specific case
plot_explanations(explanation) #plot feature by case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment