1、设置工作路径
setwd("H:/R代码/Iris")
2、读取数据
library(readxl)
IrisData
str(IrisData)
IrisData$species
head(IrisData)
3、将数据(150个)分为训练集(70%)和测试集(30%)
shuffled
n.test
train
trainset
testfullset
testset
head(trainset)
head(testset)
4、决策树分析
library(party) #载入决策树分析包
Iris_tree
+ sepal_width
+ petal_length
+ petal_width,
data = trainset) #构建决策树
print(Iris_tree) #查看决策树信息
plot(Iris_tree, main = "Decision Tree for Iris") #决策树完整图
plot(Iris_tree, type = "simple", main = "Decision Tree for Iris") #决策树简易图
利用训练集生成的决策树对测试集进行预测&#