-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no applicable method for 'predict' applied to an object of class "ranger" #56
Comments
Hi @quantumlinguist, if this is still troubling you, would you mind sharing a reproducible example for me to run on my end? |
Hi @bgreenwell, I get the same error when running exactly the code from your vignette (fastshap.Rmd).
When I run
it works, so I guess the issue must be related to the option I also used |
Hi @viola-hilbert are you on getting this error a Windows machine? |
yes! |
Instead of cl <- makeCluster(4)
registerDoParallel(cl) But do try this out on a much smaller sample for testing! For example, pass in |
Hi @brandongreenwell-8451 , I get the same error as @viola-hilbert .I also use the code from your vignette (fastshap.Rmd), and I attempted the method you mentioned(cl <- makeCluster(4)).But the error(no applicable method for 'predict' applied to an object of class...)still exist when I choose the option that parallel = TRUE. |
Hi @hlboy2333, what type of OS are you running this on? |
|
Thanks @hlboy2333, I'm having trouble reproducing the issue on my end. You may just need to pass library(fastshap)
library(ranger)
library(AmesHousing)
library(doParallel)
ames <- as.data.frame(AmesHousing::make_ames())[1:200, ] # try with a sample
X <- subset(ames, select = -Sale_Price) # features only
# Fit a random forest
set.seed(102)
(rfo <- ranger(Sale_Price ~ ., data = ames, write.forest = TRUE))
# Prediction wrapper
pfun <- function(object, newdata) {
predict(object, data = newdata)$predictions
}
cl <- makeCluster(4) # use 4 workers
registerDoParallel(cl) # register the parallel backend
system.time({ # estimate run time
ex.ames.par <- explain(rfo, X = X, pred_wrapper = pfun, nsim = 5,
adjust = TRUE, parallel = TRUE, .packages = "ranger")
}) |
Thank you so much for your help @brandongreenwell-8451. Your method worked successfully(Not only on the code you provided, but also on my own data and models (It took a while, please forgive me for being late). It solved the problem that had been bothering me for nearly a day. |
Hi @hlboy2333, glad it works now. This is more of a function of the foreach package, which is used under the hood. You can read some about it in the associated vignette: https://cran.r-project.org/web/packages/foreach/vignettes/foreach.html. You can pass additional arguments to foreach via the |
I'll leave this issue open until I can generalize the vignette example to be more system agnostic. |
I have been trying to use the fastshap package but I get this error:
task 1 failed - "no applicable method for 'predict' applied to an object of class "ranger""
If I do methods(predict), predict.ranger does appear in the list.
The text was updated successfully, but these errors were encountered: