cobbler_squad
2010-Jun-02 18:15 UTC
[R] nnet: cannot coerce class c("terms", "formula") into a data.frame
Dearest all, Objective: I am now learning neural networks. I want to see how well can train an artificial neural network model to discriminate between the two files I am attaching with this message. http://r.789695.n4.nabble.com/file/n2240582/3dMaskDump.txt 3dMaskDump.txt http://r.789695.n4.nabble.com/file/n2240582/test_vowels.txt test_vowels.txt Question: when I am attempting to run>cvc_nnet <- nnet(G ~ ., data=cvc_lda, size=1,iter=10,MaxNWts=100)I get an error saying: Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class c("terms", "formula") into a data.frame I have not encountered this error when I was running this script with previous lda results, and, I am not quite sure what the error means. Below is short (and, I hope, reproducible) code. library(nnet) cvc_nnet <- nnet(G ~ ., data=cvc_lda, size=1,iter=10,MaxNWts=100) predict(cvc_nnet,cvc_lda,type = "class") table(predict(cvc_nnet,cvc_lda,type = "class"),cvc_lda$G) cvc_nnet.out<-NULL all = c(1:52) for(n in all){ ? cvc_nnet <- nnet(G ~ ., data=cvc_lda[all != n,], CV =TRUE,size=1,iter=10,MaxNWts=100) ? ?cvc_nnet.out <- c(cvc_nnet.out,predict(cvc_nnet,cvc_lda[all == n,],type "class")) } table(cvc_nnet.out,cvc_lda$G) == to get cvc_lda: library(MASS) vowel_features <- data.frame(as.matrix(read.table(file "test_vowels.txt"))) mask_features <- data.frame(as.matrix(read.table(file = "3dmaskdump.txt"))) G <-vowel_features[,41] cvc_lda <- lda(G ~ ., data=mask_features, na.action="na.omit", CV=TRUE) Your insight is very much appreciated it! -- View this message in context: http://r.789695.n4.nabble.com/nnet-cannot-coerce-class-c-terms-formula-into-a-data-frame-tp2240582p2240582.html Sent from the R help mailing list archive at Nabble.com.
Joris Meys
2010-Jun-02 23:14 UTC
[R] nnet: cannot coerce class c("terms", "formula") into a data.frame
Without checking R or the rest of the code, the error seems quite clear to me: R finds a formula where it expects a data frame. cvc_lda is not a dataframe. Do str(cvc_lda) to check for yourself. You really need to learn this btw. Whenever you get an error, first thing to do is to check whether everything you put in the function is what you think it is, and is what R needs it to be. Before you overload the help list with questions, please take some time to read the introduction to R thoroughly. You really need to get to understand the differences between vectors or arrays, matrices, data frames, lists, ... You struggle with it quite obviously, and that's a problem we cannot solve for you. http://cran.r-project.org/doc/manuals/R-intro.pdf If there is something that is not clear to you, feel free to ask here. Cheers Joris On Wed, Jun 2, 2010 at 8:15 PM, cobbler_squad <la.foma@gmail.com> wrote:> > Dearest all, > > Objective: I am now learning neural networks. I want to see how well can > train an artificial neural network model to discriminate between the two > files I am attaching with this message. > > http://r.789695.n4.nabble.com/file/n2240582/3dMaskDump.txt 3dMaskDump.txt > http://r.789695.n4.nabble.com/file/n2240582/test_vowels.txttest_vowels.txt > > Question: when I am attempting to run > >cvc_nnet <- nnet(G ~ ., data=cvc_lda, size=1,iter=10,MaxNWts=100) > I get an error saying: > Error in as.data.frame.default(x[[i]], optional = TRUE) : > cannot coerce class c("terms", "formula") into a data.frame > > I have not encountered this error when I was running this script with > previous lda results, and, I am not quite sure what the error means. > > Below is short (and, I hope, reproducible) code. > > library(nnet) > > cvc_nnet <- nnet(G ~ ., data=cvc_lda, size=1,iter=10,MaxNWts=100) > > predict(cvc_nnet,cvc_lda,type = "class") > table(predict(cvc_nnet,cvc_lda,type = "class"),cvc_lda$G) > > cvc_nnet.out<-NULL > all = c(1:52) > > for(n in all){ > cvc_nnet <- nnet(G ~ ., data=cvc_lda[all != n,], CV > =TRUE,size=1,iter=10,MaxNWts=100) > cvc_nnet.out <- c(cvc_nnet.out,predict(cvc_nnet,cvc_lda[all == n,],type > > "class")) > } > > table(cvc_nnet.out,cvc_lda$G) > > ==> > to get cvc_lda: > > library(MASS) > > vowel_features <- data.frame(as.matrix(read.table(file > "test_vowels.txt"))) > mask_features <- data.frame(as.matrix(read.table(file = "3dmaskdump.txt"))) > G <-vowel_features[,41] > > cvc_lda <- lda(G ~ ., data=mask_features, na.action="na.omit", CV=TRUE) > > > Your insight is very much appreciated it! > > -- > View this message in context: > http://r.789695.n4.nabble.com/nnet-cannot-coerce-class-c-terms-formula-into-a-data-frame-tp2240582p2240582.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 Joris.Meys@Ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]]