0

I have divided my data set into two groups:

  1. transactions.Train (80% of the data)
  2. transactions.test (20% of the data)

Then I built the decision tree using ctree method from party package as follow:

transactions.Tree <- ctree(dt_formula, data=transactions.train)

And I can successfully apply predict method on the training set and use table function to output the result as follow:

table(predict(transactions.Tree), transactions.train$Satisfaction)

But my problem occurs when I try to output the table based on the testing set as follow:

testPred <- predict(transactions.Tree, newdata=transactions.test)
table(testPred, transactions.test$Satisfaction)

And the error is as follow:

Error in table(predict(pred = svm.pred, transactions.Tree), transactions.test$Satisfaction) : 
  all arguments must have the same length

I have done research on similar cases which suggested omitting any NA values which I did without changing the error outcome.

Can anyone help me by poniting out what's the problem here?

  • Difficult to check without a reproducible code. You should check the length of testPred and if it is not same as length of transactions.test$Satisfaction, then you should investigate further why this is happening. You can also try to predict each row of test set separately and check which row is not giving prediction. – Kumar Manglam Feb 29 '16 at 05:27
  • Your error message does not seem to conform with the preceeding code as it reads `predict(pred = svm.pred, transactions.Tree)` instead of `testPred`. Predicting SVMs on a tree probably doesn't make sense. But without a reproducible example it is impossible to say more. – Achim Zeileis Mar 01 '16 at 06:49

0 Answers0