Parallel partial dependence plot in R with ranger and pdp

Viewed 1112

I'm trying to run a two-way partial dependence plot as efficiently as possible (with parallelized computation), and am using the following specification


cluster <- makeCluster(detectCores() - 1) # convention to leave 1 core for OS
registerDoParallel(cluster)

partial(cforest_adjusted, 
pred.var = c("avg_mtg_duration", "avg_mtg_attd"), 
trim.outliers = TRUE, chull = TRUE, parallel = TRUE,
grid.resolution = 30)

The cforest_adjusted object is from the ranger library using the "maxstat" split.

I get the following error:

: ... may be used in an incorrect context: â.fun(piece, ...)â : ... may be used in an incorrect context: â.fun(piece, ...)â Error in do.ply(i) : task 1 failed - "no applicable method for 'predict' applied to an object of class "ranger""

I'm guessing I have to supply a custom predict function to the do.ply backend, but am now sure how to do this.

1 Answers

Figured it out. You need to add external libraries (e.g. ranger) like so:

partial(cforest_adjusted, 
pred.var = c("avg_mtg_duration", "avg_mtg_attd"), 
trim.outliers = TRUE, chull = TRUE, parallel = TRUE,
grid.resolution = 30,  paropts = list(.packages = "ranger"))
Related