# NOT RUN {
# First we fit a machine learning model on the Boston housing data
library("randomForest")
data("Boston", package = "MASS")
mod = randomForest(medv ~ ., data = Boston, ntree = 50)
X = Boston[-which(names(Boston) == "medv")]
# Then we explain the first instance of the dataset with the lime() method:
x.interest = X[1,]
lemon = lime(mod, X, x.interest = x.interest, k = 2)
lemon
# Look at the results in a table
lemon$data()
# Or as a plot
plot(lemon)
# Reuse the object with a new instance to explain
lemon$x.interest = X[2,]
plot(lemon)
# lime() also works with multiclass classification
library("randomForest")
mod = randomForest(Species ~ ., data= iris, ntree=50)
X = iris[-which(names(iris) == 'Species')]
# Then we explain the first instance of the dataset with the lime() method:
lemon = lime(mod, X, x.interest = X[1,], predict.args = list(type='prob'), k = 3)
lemon$data()
plot(lemon)
# You can also focus on one class
lemon = lime(mod, X, x.interest = X[1,], class = 2, predict.args = list(type='prob'), k = 2)
lemon$data()
plot(lemon)
# }
Run the code above in your browser using DataLab