2

I am using R 3.6.1, RStudio 1.2.5019 and mlr 2.15.0. Mlr ist installed and loaded. Only mlr and the packages mlr is built on are loaded.

Now, I have trained a model using train and would like to test it on new data. Therefore, I want to use the predict.WrappedModel function from mlr.

If I call ?predict.WrappedModel I get all the information in the help window.

However, if I want to run predict.WrappedModel R throws an error indicating that the function cannot be found:

my_test = predict.WrappedModel(object = my_model, task = my_task)

konnte Funktion "predict.WrappedModel" nicht finden

Even when specifying mlr as the package to look in for the function:

my_test = mlr::predict.WrappedModel(object = my_model, task = my_task)

Fehler: 'predict.WrappedModel' ist kein von 'namespace:mlr' exportiertes Objekt

I also tried using ?predict , but here I also got an error:

my_test = mlr::predict(object = my_model, task = my_task)

Fehler: 'predict' ist kein von 'namespace:mlr' exportiertes Objekt

I've already spent a lot of time trying to fix this issue and read all the related questions I had found here and on the mlr forum on github, but could not find a solution.

What am I missing here?

Thanks a lot in advance :)

TimoK
  • 23
  • 3
  • Can you post a complete example that allows to reproduce the problem please? In general, you should always use `predict` and don't need to use the `predict.*` functions directly. – Lars Kotthoff Nov 05 '19 at 16:04

1 Answers1

2

You neither need predict.WrappedModel nor mlr::predict. Both are internal functions using the generic S3 approach in R to operate based on the class of the supplied R object.

So in this case, as long as you pass a object derived from a mlr::train() call everything will just work.

Speaking with code:

library("mlr")
my_model = train(learner, task)
predict(my_model, task)
pat-s
  • 5,992
  • 1
  • 32
  • 60
  • I thought that there is a mlr-specific `mlr::predict` function (just like there is a mlr-specific `mlr::train` function), but that seems to be not the case. Instead, we just use the regular `train` function from the stats library. This misunderstanding has led me to wanting to use the mlr-specific `predict.WrappedModel` function, which I was unable to run, and posting my question. – TimoK Nov 06 '19 at 12:58
  • @TimoK Yes, `train()` is indeed not a S3 function in this case and can be called using `mlr::train()`. Such confusions are better handled in _mlr3_. Also when a question is answered on Stackoverflow, please click the green check mark so it is marked as "solved" (and optionally you can upvote the answer if you liked it). – pat-s Nov 07 '19 at 16:15