Aadhithya
2010-Jun-30 15:44 UTC
[R] how to tabulate the prediction value using table function for naive baiyes in R
Hi, I have written a code in R for classifying microarray data using naive bayes, the code is given below: library(e1071) train<-read.table("Z:/Documents/train.txt",header=T); test<-read.table("Z:/Documents/test.txt",header=T); cl <- c(c(rep("ALL",10), rep("AML",10))); cl <- factor(cl) model <- naiveBayes(train,cl); pred<-predict(model,test,type = "raw"); table(pred,cl); everything is working fine I am able to build the model and predict also but I am not able to get the confusion matrix using table function.its giving me the following error when I execute the line "table(pred,cl)" Error in table(pred,cl):all arguments must have the same length I am not sure where I am going wrong. I want the confusion matrix using table function but I am not able to get it . Please help me .Thanks in advance. -Aadhithya -- View this message in context: http://r.789695.n4.nabble.com/how-to-tabulate-the-prediction-value-using-table-function-for-naive-baiyes-in-R-tp2272742p2272742.html Sent from the R help mailing list archive at Nabble.com.
Steve Lianoglou
2010-Jun-30 19:44 UTC
[R] how to tabulate the prediction value using table function for naive baiyes in R
Hi, On Wed, Jun 30, 2010 at 11:44 AM, Aadhithya <sistaadhi at gmail.com> wrote:> > Hi, > I have written a code in R for classifying microarray data using naive > bayes, the code is given below: > library(e1071) > train<-read.table("Z:/Documents/train.txt",header=T); > test<-read.table("Z:/Documents/test.txt",header=T); > cl <- c(c(rep("ALL",10), rep("AML",10))); > cl <- factor(cl) > model <- naiveBayes(train,cl); > pred<-predict(model,test,type = "raw"); > table(pred,cl);Do you expect the predicted labels on your testing data to be the same labels you used from your training data?> everything is working fine I am able to build the model and predict also but > I am not able to get the confusion matrix using table function.its giving me > the following error when I execute the line "table(pred,cl)" > Error in table(pred,cl):all arguments must have the same length > I am not sure where I am going wrong.Here's a piece of advice you might want to consider: stop driving blindly. The error tells you where you are going wrong, so take some time to read it a bit more closely. Then take another minute or two to see what your "pred" and "cl" vectors look like. -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact