Daniel Stahl
2011-Feb-27 21:59 UTC
[R] regularized dfa rda (Klar): problems with predictions
Dear all, I am trying to do a n-fold cross-validation for a regularized discrimant function analysis using rda from the package klaR. However, I have problems to predict the groups from the test/validation sample. The exmaples of the R documantation and some online webpage also do not work. Does anybody know what I have done wrong? Here my code # I want to use the first 6 observations for validationg the model, case 7 to 36 are # used for the trianing: n_fold<-sample(1:36,36) testset<- n_fold[1:6] trainset<- n_fold[-(1:6)] # regularized DFA with default setting (works fine) z <- rda(group ~ ., data=test[trainset,]) #Now the prediction: a<-predict(z,data=test[testset,])$class Error in predict.rda(z, data = test[testset, ]) : A new data to predict must be supplied. Whatever I do I always get the same error message (including examples form help) Thanks a lot in advance! Best wishes, Daneil --
Uwe Ligges
2011-Feb-28 17:27 UTC
[R] regularized dfa rda (Klar): problems with predictions
On 27.02.2011 22:59, Daniel Stahl wrote:> Dear all, I am trying to do a n-fold cross-validation for a regularized discrimant function analysis using rda from the package klaR. However, I have problems to predict the groups from the test/validation sample. The exmaples of the R documantation and some online webpage also do not work. Does anybody know what I have done wrong? > > Here my code > # I want to use the first 6 observations for validationg the model, case 7 to 36 are > # used for the trianing: > n_fold<-sample(1:36,36) > testset<- n_fold[1:6] > trainset<- n_fold[-(1:6)] > # regularized DFA with default setting (works fine) > z<- rda(group ~ ., data=test[trainset,])It is advisable to use a fixed set for lambda and gamma here. The optimizer used for finding "optimal" values may fail easily.> #Now the prediction: > a<-predict(z,data=test[testset,])$classIn predict, you need to use "newdata" rather than "data". Uwe Ligges> Error in predict.rda(z, data = test[testset, ]) : > A new data to predict must be supplied. > > > Whatever I do I always get the same error message (including examples form help) > > Thanks a lot in advance! > Best wishes, Daneil > >
Daniel Stahl-2 wrote> Error in predict.rda(z, data = test[testset, ]) : > A new data to predict must be supplied.For anyone encountering this problem, it stems from having both the klaR and rda libraries loaded. rda gives this error message because its predict.rda is defined: function (object, x, y, xnew, prior, alpha, delta, type = c("class", "posterior", "nonzero"), trace = FALSE, ...) and if (missing(xnew)) { stop("A new data to predict must be supplied.") } unload the rda package: detach("package:rda", unload=TRUE) -- View this message in context: http://r.789695.n4.nabble.com/regularized-dfa-rda-Klar-problems-with-predictions-tp3327188p4710913.html Sent from the R help mailing list archive at Nabble.com.