简体   繁体   English

带有 Rpart 的 R 分类树

[英]R classification tree with Rpart

I have some data which I would like to segment.我有一些我想分割的数据。 My first thought was classification tree in R from Rpart package.我的第一个想法是来自 Rpart 包的 R 中的分类树。 My training data consists of many explanatory variables and one 0-1 response variable named "sold".我的训练数据由许多解释变量和一个名为“sold”的 0-1 响应变量组成。 The response value "1" appears in about 80% of rows.响应值“1”出现在大约 80% 的行中。 When I try to build a tree with rpart(sold~., training_data, method = "class") , R is unable to create a tree.当我尝试使用rpart(sold~., training_data, method = "class")构建树时,R 无法创建树。 I suppose that the reason is that it can't find any segments which differ very much from one another.我想原因是它找不到任何彼此差异很大的段。 After quick inspection of the data, I expect that my tree should look like that left node will have 85% of sold and right node will have 75% of sold.快速检查数据后,我希望我的树看起来应该像左节点将有 85% 的销售量和右节点将有 75% 的销售量。

Is there any way to create a classification tree on such data set?有没有办法在这样的数据集上创建分类树?

I had same problem.我有同样的问题。 It seems to be a problem about 'cp'.似乎是关于'cp'的问题。 Refer to my code:参考我的代码:

tr1<-rpart(bad~group+amount, data=ra, 
control=rpart.control(minsplit=5, cp=0.001),method='class')

When I run this, it worked.当我运行它时,它起作用了。 when I increase cp level (eg 0.005), it didn't work.当我增加 cp 级别(例如 0.005)时,它不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM