Closed shihuang047 closed 3 years ago
Hi, you need to manually set the predict function like this:
pfun <- function(object, newdata) predict(object, data = newdata)$predictions
model = Predictor$new(rf, data = X, y = Boston$medv, predict.fun = pfun)
R package
ranger
is a fast implementation of Random Forests using C++ (https://github.com/imbs-hl/ranger), which I have been used a lot in my large datasets. I just quickly ran the example code you provided on the front page and replaced the model fromRandomForest
package with one byranger
.library("iml") library("randomForest") data("Boston", package = "MASS") rf = randomForest(medv ~ ., data = Boston, ntree = 50) X = Boston[which(names(Boston) != "medv")] model = Predictor$new(rf, data = X, y = Boston$medv) effect = FeatureEffects$new(model) effect$plot(features = c("lstat", "age", "rm"))
rf = ranger::ranger(medv ~ ., data = Boston, ntree = 50) X = Boston[which(names(Boston) != "medv")] model = Predictor$new(rf, data = X, y = Boston$medv) effect = FeatureEffects$new(model) Error in feature_effect(feature, predictor = predictor, method = method, : task 1 failed - "cannot coerce class ‘"ranger.prediction"’ to a data.frame"