1. Download R for Windows (http://cran.csie.ntu.edu.tw/)
2. Install and RUN
3.
使用rpart套件,iris data
>library(rpart)
> data(iris)
> np = ceiling(0.1*nrow(iris)) #
> np
[1] 15
> test.index = sample(1:nrow(iris),np)
> iris.testdata = iris[test.index,]
> iris.traindata = iris[-test.index,]
> iris.tree = rpart(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, method="class", data=iris.traindata)
> iris.tree
n= 135
node), split, n, loss, yval, (yprob)
* denotes terminal node
1) root 135 89 versicolor (0.31851852 0.34074074 0.34074074)
2) Petal.Length< 2.45 43 0 setosa (1.00000000 0.00000000 0.00000000) *
3) Petal.Length>=2.45 92 46 versicolor (0.00000000 0.50000000 0.50000000)
6) Petal.Width< 1.75 50 5 versicolor (0.00000000 0.90000000 0.10000000) *
7) Petal.Width>=1.75 42 1 virginica (0.00000000 0.02380952 0.97619048) *
> plot(iris.tree); text(iris.tree)
>
沒有留言:
張貼留言