1

I would like to have all the predictions of a random forest from the package {ranger} stored in an ml3 Prediction Object, and then use the predictions of the individual trees as features for another learner.

The following code then follows to the following error message in R.

Code:

library("mlr3")
library("mlr3learners")

task = tsk("iris")
learner = lrn("classif.ranger", predict.all = TRUE)

# Train
train_set = sample(task$nrow, 0.8 * task$nrow)
test_set = setdiff(seq_len(task$nrow), train_set)

learner$train(task, row_ids = train_set)

# Predition
prediction = learner$predict(task, row_ids = test_set)
print(prediction)

Error:

Error in check_prediction_data.PredictionDataClassif(pdata) :
Assertion on 'as_factor(pdata$response, levels = lvls)' failed: Must have length 30, but has length 15000.

Can someone help me to solve this issue?

RaphaelS
  • 839
  • 4
  • 14
  • I do not think this is supported in mlr3 for ranger. You can request this feature here: https://github.com/mlr-org/mlr3learners/. – missuse Jan 31 '21 at 08:42
  • I've opened a PR to fix this, predict.all isn't handled by mlr3 currently https://github.com/mlr-org/mlr3learners/pull/172 – RaphaelS Jan 31 '21 at 10:42
  • 1
    The PR from RahphaelS is not really helping with your issue. What you describe would best fit into a pipe operator in mlr3pipelines. I've opened an issue over there: https://github.com/mlr-org/mlr3pipelines/issues/561 – Michel Feb 01 '21 at 21:35
  • It happens to me, and I am not using predict.all parameter. Must be an issue related with the interacction between ranger and mlr3 as wraper. – Colibri Jun 18 '21 at 01:17

0 Answers0