en un clic
lime
// R lime package for local explanations. Use for explaining individual predictions with local interpretable models.
// R lime package for local explanations. Use for explaining individual predictions with local interpretable models.
R language data analysis and visualization skill. Use when user asks to (1) run R scripts or code, (2) install/update R packages, (3) perform data analysis with R, (4) create visualizations with ggplot2/plotly, (5) statistical analysis, (6) data manipulation with tidyverse/dplyr/data.table. Triggers on keywords like "R语言", "R脚本", "ggplot", "tidyverse", "数据分析", "可视化".
R DALEX package for model explanations. Use for explaining complex machine learning models.
R iml package for interpretable ML. Use for model-agnostic interpretability methods.
R packages for ML interpretability. Use for explaining and interpreting machine learning models.
R vip package for variable importance. Use for computing and visualizing variable importance scores.
R machine learning packages. Use for classification, regression, clustering, deep learning, gradient boosting (xgboost, lightgbm), random forests, neural networks, and time series forecasting.
| name | lime |
| description | R lime package for local explanations. Use for explaining individual predictions with local interpretable models. |
Local Interpretable Model-agnostic Explanations.
library(lime)
# Create explainer
explainer <- lime(
x = train_data,
model = model
)
# Explain single prediction
explanation <- explain(
x = new_data[1, ],
explainer = explainer,
n_features = 5
)
# Plot
plot_features(explanation)
# Explain multiple
explanation <- explain(
x = new_data[1:4, ],
explainer = explainer,
n_features = 5
)
# Plot all
plot_features(explanation)
# Plot explanations
plot_explanations(explanation)
explanation <- explain(
x = new_data,
explainer = explainer,
n_features = 5, # Number of features
n_labels = 1, # Number of labels (classification)
n_permutations = 5000, # Permutations for sampling
feature_select = "auto" # Feature selection method
)
# Methods
explanation <- explain(x, explainer, n_features = 5,
feature_select = "auto") # Automatic
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")
# For text classification
explainer <- lime(
x = train_text,
model = text_model,
preprocess = function(x) {
# Tokenize/vectorize text
}
)
explanation <- explain(
x = new_text,
explainer = explainer,
n_features = 10
)
# Highlight text
plot_text_explanations(explanation)
# For image classification
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)
# Define predict function
model_type.my_model <- function(x, ...) "classification"
predict_model.my_model <- function(x, newdata, ...) {
predict(x, newdata, type = "prob")
}
# Use with lime
explainer <- lime(train_data, my_model)