Subscribe to DSC Newsletter

Question about R error: 'all arguments must have the same length'

Hi Everyone,

i am using R to fit svms using the e1071 package. Everything seems fine when i train the model, and even when validating with a different data-set. the training data-set has 1500 records and 17 variables. When i attempt to generate a classification matrix i obtain the following error:

“Error in table(pred = prediction, true = observed) : all arguments must have the same length”

below is my R code from model fitting up to when i get the error. I have checked the length of the length(sum.pred)=1500 while the length of the length(CARDTRAIN)=17. please assist in helping me figure out the above error.

svm.model <- svm(FRAUD_IND ~ ., data = CARDTRAIN2,family=binomial,prob.model=TRUE)

svm.pred <- predict(svm.model, CARDTRAIN2,decision.values=TRUE,probability=TRUE)

table(pred=svm.pred, true=CARDTRAIN2)#error

Tags: Error:all, R, SVM, arguments, have, length, must, same, the

Views: 26824

Reply to This

Replies to This Discussion

Hi Mark,

You get an error because you give a complete data.frame as a second argument to table instead of labels column only.

Assuming that your label column is "FRAUD_IND" it should go like this:

table(pred=svm.pred, true=CARDTRAIN2$FRAUD_IND)


that also doesnt work


On Data Science Central

© 2021   TechTarget, Inc.   Powered by

Badges  |  Report an Issue  |  Privacy Policy  |  Terms of Service