I'm trying to use the iml package in R and I am getting an error from FeatureEffects$new
that I cannot make sense of. I am training a random forest using caret
, then I am squeezing the model into a Predictor
object as required by iml
. And finally I'm trying to compute FeatureEffects
and it throws this error:
Error in diag(dists.cumulated) : Can only replace the diagonal of a matrix
I have a short code snippet from the documentation below and my version of it beneath. The only difference is that I am using caret
to train my model but this is explicitly mentioned as supported in the documentation. Does anyone have experience with caret
and iml
and has a clue what is going on? Needless to say that the code from the documentation throws no such error...
Code snippet from iml
documentation:
# Train a random forest on the Boston dataset:
library("rpart")
data("Boston", package = "MASS")
rf <- rpart(medv ~ ., data = Boston)
# Squeeze the model into a Predictor object
mod <- Predictor$new(rf, data = Boston)
# Compute the accumulated local effects for all features
eff <- FeatureEffects$new(mod, method="ale")
Adopted code snippet using my caret
based model:
# Train a random forest on my dataset using caret:
rf.model <- train(input.train[, names(input.rf) != dependent, drop=FALSE], input.train[, names(input.rf) == dependent], method="rf", ntree=ntree, metric=metric, trControl=cntrl, tuneGrid=tunegrid, nodesize=floor(nrow(input.train)*(nodesize/100)), importance=TRUE)
# Squeeze the model into a Predictor object
mod <- Predictor$new(rf.model, data=input.train)
# Compute ale effects for all features
eff <- FeatureEffects$new(mod, method="ale")