数据挖掘算法R语言实现之决策树

Posted 大数据挖掘DT数据分析

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据挖掘算法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.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 <- ctree(Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data=iris)

> print(iris_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; criterion = 1, statistic = 140.264
2)* weights = 50
1) Petal.Length > 1.9
3) Petal.Width <= 1.7; criterion = 1, statistic = 67.894
4) Petal.Length <= 4.8; criterion = 0.999, statistic = 13.865
5)* weights = 46
4) Petal.Length > 4.8
6)* weights = 8
3) Petal.Width > 1.7
7)* weights = 46

> plot(iris_ctree)

数据挖掘算法R语言实现之决策树


plot(iris_ctree, type="simple")

数据挖掘算法R语言实现之决策树


小编很负责地提醒您:

【1】一定要在订单的备注栏填写邮箱,以便通过邮箱发资料;

下载资料

以上是关于数据挖掘算法R语言实现之决策树的主要内容,如果未能解决你的问题,请参考以下文章

数据挖掘常用算法之决策树算法

R语言基于R语言的数据挖掘之决策树

R语言实战应用精讲50篇(三十一)-R语言实现决策树(附R语言代码)

数据分享|R语言逻辑回归Naive Bayes贝叶斯决策树随机森林算法预测心脏病|附代码数据

数据分享|R语言逻辑回归Naive Bayes贝叶斯决策树随机森林算法预测心脏病|附代码数据

R(rattle)实现决策树算法