Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Simple Example



> sub <- c(sample(1:150, 75))  # Random sampling
> fit <- rpart(Species ~ ., data=iris, subset=sub)
> fit
n= 75

node), split, n, loss, yval, (yprob)
      * denotes terminal node

1) root 75 47 virginica (0.2800000 0.3466667 0.3733333)
  2) Petal.Length< 2.5 21  0 setosa (1.0000000 0.0000000 0.0000000) *
  3) Petal.Length>=2.5 54 26 virginica (0.0000000 0.4814815 0.5185185)
    6) Petal.Length< 5.05 29  3 versicolor (0.0000000 0.8965517 0.1034483) *
    7) Petal.Length>=5.05 25  0 virginica (0.0000000 0.0000000 1.0000000) *

> table(predict(fit, iris[-sub,], type="class"), iris[-sub, "Species"])

             setosa versicolor virginica
  setosa         29          0         0
  versicolor      0         23         6
  virginica       0          1        16



Copyright © 2004-2006 [email protected]
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.