Re: [R] help with predict.lda
Thanks all so much for your help! I went out for 2 days vacation and could not reply your guys email. Yes, the CV=False works. Thanks again! On Sun, Jul 4, 2010 at 2:47 AM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2010-07-03 21:33, Changbin Du wrote: HI, Dear community, I am using the linear discriminant analysis to build model and make new predictions: dim(train) #training data [1] 1272 22 dim(valid) # validation data [1] 140 22 lda.fit- lda(out ~ ., data=train, na.action=na.omit, CV=TRUE) # model fitting of linear discriminant analysis on training data predict(lda.fit, valid) # make prediction on validation data Error in UseMethod(predict) : no applicable method for 'predict' applied to an object of class list Can anyone help with this? Suggestions: 0. lda() is not a function in the base installation of R; I'll assume that you mean MASS::lda. 1. ask yourself what you expect from setting CV = TRUE. 2. *carefully* (re)read the help pages for lda (especially the Value section) and for predict.lda (the 'object' definition). 3. use CV = FALSE 4. whenever problems arise, *first* use str() on your objects to see what you've got. 5. finally, do provide *reproducible* code; here, you could have used the example on the help page. -Peter Ehlers Thanks so much! -- Sincerely, Changbin -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with predict.lda
On 2010-07-03 21:33, Changbin Du wrote: HI, Dear community, I am using the linear discriminant analysis to build model and make new predictions: dim(train) #training data [1] 1272 22 dim(valid) # validation data [1] 140 22 lda.fit- lda(out ~ ., data=train, na.action=na.omit, CV=TRUE) # model fitting of linear discriminant analysis on training data predict(lda.fit, valid) # make prediction on validation data Error in UseMethod(predict) : no applicable method for 'predict' applied to an object of class list Can anyone help with this? Suggestions: 0. lda() is not a function in the base installation of R; I'll assume that you mean MASS::lda. 1. ask yourself what you expect from setting CV = TRUE. 2. *carefully* (re)read the help pages for lda (especially the Value section) and for predict.lda (the 'object' definition). 3. use CV = FALSE 4. whenever problems arise, *first* use str() on your objects to see what you've got. 5. finally, do provide *reproducible* code; here, you could have used the example on the help page. -Peter Ehlers Thanks so much! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with predict.lda
On Jul 3, 2010, at 11:33 PM, Changbin Du wrote: HI, Dear community, I am using the linear discriminant analysis to build model and make new predictions: dim(train) #training data [1] 1272 22 dim(valid) # validation data [1] 140 22 lda.fit - lda(out ~ ., data=train, na.action=na.omit, CV=TRUE) # model fitting of linear discriminant analysis on training data predict(lda.fit, valid) # make prediction on validation data Error in UseMethod(predict) : no applicable method for 'predict' applied to an object of class list The predict methods are very picky with what can be used as input. They need to have a dataframe with exactly the same variable names as were used in the rhs of the formula given to the fitting function. In this case that would be all columns in train except $out. Reasoning under the assumption that valid looks just like train at the moment, I think it's possible that you need to remove the $out column from the valid object since it was not on the rhs. Of course it is also possible that valid is even more poorly constructed than I think, so any further questions should adhere to Peter's admonitions as well as including str(train) and str(valid). Can anyone help with this? -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with predict.lda
On Jul 4, 2010, at 7:37 AM, David Winsemius wrote: On Jul 3, 2010, at 11:33 PM, Changbin Du wrote: HI, Dear community, I am using the linear discriminant analysis to build model and make new predictions: dim(train) #training data [1] 1272 22 dim(valid) # validation data [1] 140 22 lda.fit - lda(out ~ ., data=train, na.action=na.omit, CV=TRUE) # model fitting of linear discriminant analysis on training data predict(lda.fit, valid) # make prediction on validation data Error in UseMethod(predict) : no applicable method for 'predict' applied to an object of class list The predict methods are very picky with what can be used as input. They need to have a dataframe with exactly the same variable names as were used in the rhs of the formula given to the fitting function. That is still mostly true except that it should say includes all of the variables used in the rhs. In this case that would be all columns in train except $out. Reasoning under the assumption that valid looks just like train at the moment, I think it's possible that you need to remove the $out column from the valid object since it was not on the rhs. That is not correct. The example in MASS::lda clearly shows the use of a dataframe that has the grouping variable left in a dataframe offered to predict(). Of course it is also possible that valid is even more poorly constructed than I think, so any further questions should adhere to Peter's admonitions as well as including str(train) and str(valid). So that is even more true. Can anyone help with this? -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help with predict.lda
HI, Dear community, I am using the linear discriminant analysis to build model and make new predictions: dim(train) #training data [1] 1272 22 dim(valid) # validation data [1] 140 22 lda.fit - lda(out ~ ., data=train, na.action=na.omit, CV=TRUE) # model fitting of linear discriminant analysis on training data predict(lda.fit, valid) # make prediction on validation data Error in UseMethod(predict) : no applicable method for 'predict' applied to an object of class list Can anyone help with this? Thanks so much! -- Sincerely, Changbin -- [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.