Assertion on 'task' failed: Must inherit from class 'Task', but has class 'data.frame'

489 Views Asked by At

I trained an XGBoost model using mlr package. I need to make a prediction on a test set that does not have the target variable. I should just predict the target variable. If I do this:

testF.pred <- predict(xgmodel,X_test)

The error is:

Error in predict.WrappedModel(xgmodel, X_test) : 
Assertion on 'task' failed: Must inherit from class 'Task', but has class 'data.frame'.

I should define a task to predict the target variable. However, If I want to create a task,

mytest_task <- makeClassifTask(data = X_test)
testF.pred <- predict(xgmodel,mytest_task)

The error is:

Error in assertString(target) : 
  argument "target" is missing, with no default

How I should make a task to do prediction on a dataset without the target variable?

1

There are 1 best solutions below

0
Lars Kotthoff On

You can use the newdata argument for this, i.e.

predict(xgmodel, newdata = X_test)

See the help page for more information.

On a separate note, I recommend switching to mlr3, the successor of mlr.