1

I encountered this error message while I used prediction after training.

Anyone knows where I went wrong?

# Create train and test tasks
trainTask <- makeClassifTask(data = data.train, target = "SetAppt", positive = "1")
testTask <- makeClassifTask(data = data.test, target = "SetAppt", positive = "1")

ksvm <- makeLearner("classif.ksvm", predict.type = "prob")
tuned.svm <- setHyperPars(ksvm, par.vals = res$x)
getParamSet(tuned.svm)
getHyperPars(tuned.svm)

# Train final model with whole training set
svm.train <- train(tuned.svm, trainTask)

# Predict final model with test set
predict.svm <- predict(svm.train, testTask, subset = y.test) 

# I also tried this
predict.svm <- predict(svm.train, newdata = x.test)
jw_code
  • 21
  • 2
  • 2
    Hi and welcome! The code that you provide in your question should be self-contained. That means it should be reproducible. In your code, there are function calls of functions that are not defined in your snippet. That makes it hard to help. Also, state in which line the error appears. – otwtm Jan 15 '20 at 17:34
  • 1
    predict should not be applied on a "test" task but on a data frame - second way mentioned here: https://mlr.mlr-org.com/articles/tutorial/predict.html. – missuse Jan 15 '20 at 21:00
  • @missuse, I have read the article you linked before and I have tried predict(svm.train, newdata = x.test), in which x.test is a dataframe. It gave me the same error. I thought it might be caused by called multiple wrapper function which confused the model. tuned.svm is a wrapModel of makeLearner and setHyperPars. I'll try directly feed makeLearner with hyper-parameter set to see if it will solve the problem. Another interesting thing is if I use predict.type = "response", it worked. – jw_code Jan 16 '20 at 18:38
  • If you could post a reproducible example with some inbuilt data set I could provide more help. I do not think the model got confused. – missuse Jan 16 '20 at 19:05

0 Answers0