[R] computing misclassification table for tree objects
Marc R. Feldesman
feldesmanm at pdx.edu
Sat Jan 5 05:18:52 CET 2002
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list