0

An example with iris. We have some data, called tr.

df = iris
set.seed(1)
sp = sample(nrow(iris), 0.7*nrow(iris))
tr = df[sp,]
newdata = df[-sp,]

We build a model in mlr3 with the data we have:

tsk = TaskClassif$new(id="A", backend=tr, target="Species")
lrn = mlr_learners$get("classif.rpart")
train_set <- sample(tsk$nrow, 0.8*tsk$nrow)
test_set <- setdiff(seq_len(tsk$nrow), train_set)
# train the model
lrn$train(tsk, row_ids = train_set)
# predict data
pred <- lrn$predict(tsk, row_ids = test_set)

Now I want to predict the newdata with the model I built, but I only find row_ids as an argument to predict. The newdata dataset has no row_ids in tsk. I know that I can incorporate these data into the model and retrain. But my question is: Is there any way to predict without retraining the tsk?

Thank you!

ocap
  • 26
  • 4
  • 1
    There's also a `newdata` argument, just like in mlr 2. – Lars Kotthoff May 03 '20 at 18:36
  • Thank you Lars. Sorry if I am clumsy, but if I write: pred2 = lrn$predict(tsk, newdata=newdata), I get unused argument (newdata = newdata). Where should I put this newdata argument? – ocap May 04 '20 at 09:20
  • 2
    Ok, Thank you. I found it: predict(lrn, newdata). Sorry for my clumsiness – ocap May 04 '20 at 09:42

0 Answers0