| name | lime |
| description | R lime package for local explanations. Use for explaining individual predictions with local interpretable models. |
lime
Local Interpretable Model-agnostic Explanations.
Setup
library(lime)
explainer <- lime(
x = train_data,
model = model
)
Explain Predictions
explanation <- explain(
x = new_data[1, ],
explainer = explainer,
n_features = 5
)
plot_features(explanation)
Multiple Predictions
explanation <- explain(
x = new_data[1:4, ],
explainer = explainer,
n_features = 5
)
plot_features(explanation)
plot_explanations(explanation)
Options
explanation <- explain(
x = new_data,
explainer = explainer,
n_features = 5,
n_labels = 1,
n_permutations = 5000,
feature_select = "auto"
)
Feature Selection
explanation <- explain(x, explainer, n_features = 5,
feature_select = "auto")
explanation <- explain(x, explainer, n_features = 5,
feature_select = "forward_selection")
explanation <- explain(x, explainer, n_features = 5,
feature_select = "highest_weights")
explanation <- explain(x, explainer, n_features = 5,
feature_select = "lasso_path")
Text Data
explainer <- lime(
x = train_text,
model = text_model,
preprocess = function(x) {
}
)
explanation <- explain(
x = new_text,
explainer = explainer,
n_features = 10
)
plot_text_explanations(explanation)
Image Data
explainer <- lime(
x = train_images,
model = image_model,
preprocess = image_prep
)
explanation <- explain(
x = new_image,
explainer = explainer,
n_superpixels = 50,
weight = 10
)
plot_image_explanation(explanation)
Custom Models
model_type.my_model <- function(x, ...) "classification"
predict_model.my_model <- function(x, newdata, ...) {
predict(x, newdata, type = "prob")
}
explainer <- lime(train_data, my_model)