Borut Flis
Borut Flis

Reputation: 16415

Cross validation in R

I have a problem cross validating a dataset in R.

mypredict.rpart <- function(object, newdata){
                      predict(object, newdata, type = "class")
                   }
res <- errorest(win~., data=df, model = rpart, predict = mypredict.rpart)

I get this error.

Error in predict.rpart(object, newdata, type = "class") : Invalid prediction for rpart object

My dataset is made out of 16 numerical atributes and win is has two factor 0 and 1. You can download the dataset on link

Upvotes: 6

Views: 7179

Answers (1)

John Colby
John Colby

Reputation: 22588

If you're doing classification, win should be a factor.

df$win = factor(df$win)

Then your code works for me:

> res

Call:
errorest.data.frame(formula = win ~ ., data = df, model = rpart, 
    predict = mypredict.rpart)

     10-fold cross-validation estimator of misclassification error 

Misclassification error:  0.4844 

Upvotes: 9

Related Questions