giuseppec / iml

iml: interpretable machine learning R package
https://giuseppec.github.io/iml/
Other
492 stars 87 forks source link

FeatureImp fails when using mlr PreprocWrapper using parallel processing #99

Open lucasxteixeira opened 4 years ago

lucasxteixeira commented 4 years ago

Hi, First of all, iml is an awesome package and I want to say thank you for you effort on it. I'm getting a weird problem when using a mlr model with preprocessing only when using parallel processing: no applicable method for 'predict' applied to an object of class "preProcess" Reproducible example below:

library(mlr)
library(ranger)
library(iml)
data("iris")
tsk = mlr::makeClassifTask(data = iris, target = "Species")
lrn = mlr::makeLearner("classif.ranger", predict.type = "prob")
preproc_lrn = mlr::makePreprocWrapperCaret(lrn)
mod = mlr:::train(preproc_lrn, tsk)

X = iris[which(names(iris) != "Species")]
predictor = Predictor$new(mod, data = X, y = iris$Species)

library("doParallel")
cl = makePSOCKcluster(2)
registerDoParallel(cl)
imp = FeatureImp$new(predictor, loss = "ce", parallel = TRUE)
stopCluster(cl)

If I don't use a parallel backend it works perfectly:

imp = FeatureImp$new(predictor, loss = "ce")

christophM commented 4 years ago

Thanks for reporting this. Error message is:

Error in estimate_feature_imp(feature, data.sample = data.sample, y = y,  : 
  task 1 failed - "no applicable method for 'predict' applied to an object of class "preProcess""

I will look into this. First idea: Seems like preProcess is not exported