thomasp85 / lime

Local Interpretable Model-Agnostic Explanations (R port of original Python package)
https://lime.data-imaginist.com/
Other
481 stars 109 forks source link

Allow `plot_features(cases = )` to accept integer indices even when `x` has rownames #194

Open mattansb opened 10 months ago

mattansb commented 10 months ago
library(lime)
library(MASS)

iris_test <- iris[1, 1:4]
iris_train <- iris[-1, 1:4]
iris_lab <- iris[[5]][-1]
model <- lda(iris_train, iris_lab)

explanation <- lime(iris_train, model)
explanations <- explain(iris_test, explanation, n_labels = 1, n_features = 2)

plot_features(explanations, cases = 1)

When the data frame X to be explained has rownames, cases must be a character. It would be great if cases would also accept integer indices here:

rownames(iris_test) <- "flower"
explanations <- explain(iris_test, explanation, n_labels = 1, n_features = 2)

plot_features(explanations, cases = 1)
#> Error: No explanations to plot

plot_features(explanations, cases = "flower")

Created on 2023-11-12 with reprex v2.0.2