Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross validation in R

Tags:

validation

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

like image 297
Borut Flis Avatar asked Dec 05 '11 21:12

Borut Flis


1 Answers

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 
like image 108
John Colby Avatar answered Sep 30 '22 08:09

John Colby