《R语言学习笔记决策树.docx》由会员分享,可在线阅读,更多相关《R语言学习笔记决策树.docx(2页珍藏版)》请在三一办公上搜索。
1、R语言学习笔记决策树R语言学习笔记决策树 library(party)导入数据包 str(iris) 集中展示数据文件的结构 data.frame: 150 obs. of 5 variables: 150条观测值,5个变量 $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 . $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 . $ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 . $ Petal
2、.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 . $ Species : Factor w/ 3 levels setosa,versicolor,.: 1 1 1 1 1 1 1 1 1 1 . Call function ctree to build a decision tree. The first parameter is a formula, which defines a target variable and a list of independent variables. iris_ctree print(iris_
3、ctree) Conditional inference tree with 4 terminal nodes Response: Species Inputs: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width Number of observations: 150 1) Petal.Length 1.9 3) Petal.Width = 1.7; criterion = 1, statistic = 67.894 4) Petal.Length 4.8 6)* weights = 8 3) Petal.Width 1.7 7)* weights = 46 plot(iris_ctree) plot(iris_ctree, type=simple)