R语言实现决策树
以鸢尾花数据集作为算例说明
library(rpart)
iris.rp = rpart(Species~., data=iris, method="class")
plot(iris.rp, uniform=T, branch=0, margin=0.1, main=“ClassificationTree”)
text(iris.rp, use.n=T, fancy=T, col="blue")
R语言实现决策树
ßRule 1: if Petal.Length>=2.45&Petal.Width<1.75, then it is versicolor(0/49/5)
ßRule2: if Petal.Length>=2.45&Petal.Width>=1.75, then it is virginica(0/1/45)
ßRule 3: if Petal.Length<2.45, then it is setosa(50/0/0)