Bagged Trees Prediction

Dear Dr. Ballings,

I spoke to you about this in office hours.

I ran this code to create one bagged tree:

tree <- rpart(yTRAIN ~ ., BasetableTRAIN)
predTREE <- predict(tree,BasetableTEST,type="prob")[,2]

I got this error message:

Error in predict.rpart(tree, BasetableTEST, type = "prob") :
Invalid prediction for "rpart" object

How would you suggest fixing this problem?

Thanks for your help.

Answers and follow-up questions

Answer or follow-up question 1

Dear student,

Is yTRAIN a factor?

Can you show me the output of str(output)?

Michel Ballings

Sign in to be able to add an answer or mark this question as resolved.