David Marimont
2002-Jan-05 00:36 UTC
[R] computing misclassification table for tree objects
I have a classification tree that I computed via the tree function (in the tree package). I'd like to compute a misclassification table (if that's the right term) on the data used to compute the tree. That is, I want to compute a table with the different classes (i.e.,levels of the response factor) on the rows and the columns, and where entry [i,j] is the number of times the tree classified an observation of class i as one of class j. My guess is that there's a simple way to do this, but I can't figure out how. Does anybody know? Thanks. David Marimont -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Marc R. Feldesman
2002-Jan-05 04:18 UTC
[R] computing misclassification table for tree objects
At 04:36 PM 1/4/02, David Marimont wrote: >I have a classification tree that I computed via the tree function >(in the tree package). I'd like to compute a misclassification table >(if that's the right term) on the data used to compute the tree. That >is, I want to compute a table with the different classes (i.e.,levels of the >response factor) on the rows and the columns, and where entry [i,j] is >the number of times the tree classified an observation of class i as >one of class j. > predict.tree(mytreeobject, type="class") will get you the predicted classes from the computed tree object (mytreeobject). Suppose rawdata$realclass is the vector containing the original classifications used to generate mytreeobject. Then, something like: >table(rawdata$realclass, predict(mytreeobject)) # or reversed if you like should give you the contingency table (or confusion matrix) you're looking for. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._