The iml
package can now handle bigger datasets. Earlier
problems with exploding memory have been fixed for
FeatureEffect
, FeatureImp
and
Interaction
. It’s also possible now to compute
FeatureImp
and Interaction
in parallel. This
document describes how.
First we load some data, fit a random forest and create a Predictor object.
set.seed(42)
library("iml")
library("randomForest")
data("Boston", package = "MASS")
<- randomForest(medv ~ ., data = Boston, n.trees = 10)
rf <- Boston[which(names(Boston) != "medv")]
X <- Predictor$new(rf, data = X, y = Boston$medv) predictor
Parallelization is supported via the {future} package. All you need
to do is to choose a parallel backend via
future::plan()
.
library("future")
library("future.callr")
# Creates a PSOCK cluster with 2 cores
plan("callr", workers = 2)
Now we can easily compute feature importance in parallel. This means that the computation per feature is distributed among the 2 cores I specified earlier.
<- FeatureImp$new(predictor, loss = "mae")
imp library("ggplot2")
plot(imp)
That wasn’t very impressive, let’s actually see how much speed up we get by parallelization.
::system_time({
benchplan(sequential)
$new(predictor, loss = "mae")
FeatureImp
})#> process real
#> 2.37s 2.38s
::system_time({
benchplan("callr", workers = 2)
$new(predictor, loss = "mae")
FeatureImp
})#> process real
#> 2.35s 5.3s
A little bit of improvement, but not too impressive. Parallelization is more useful in the case where the model uses a lot of features or where the feature importance computation is repeated more often to get more stable results.
::system_time({
benchplan(sequential)
$new(predictor, loss = "mae", n.repetitions = 20)
FeatureImp
})#> process real
#> 8.77s 8.73s
::system_time({
benchplan("callr", workers = 2)
$new(predictor, loss = "mae", n.repetitions = 20)
FeatureImp
})#> process real
#> 2.42s 8.44s
Here the parallel computation is twice as fast as the sequential computation of the feature importance.
The parallelization also speeds up the computation of the interaction statistics:
::system_time({
benchplan(sequential)
$new(predictor)
Interaction
})#> process real
#> 19s 18.8s
::system_time({
benchplan("callr", workers = 2)
$new(predictor)
Interaction
})#> process real
#> 2.4s 13.1s
Same for FeatureEffects
:
::system_time({
benchplan(sequential)
$new(predictor)
FeatureEffects
})#> process real
#> 922ms 910ms
::system_time({
benchplan("callr", workers = 2)
$new(predictor)
FeatureEffects
})#> process real
#> 9.55s 14.13s