R

时间:2017-11-28 22:32:33

标签: r tree decision-tree pruning

所以我有一个决策树“c.tree1”,有3个不同的CP值。现在我想用精确的CP值修剪它,但结果与具有3个CP值的“c.tree1”相同。这有点奇怪吗?

c.tree1 <- rpart(certified ~ grade + assignment, 
    data = M1, method = "class")
printcp(c.tree1)

结果是:

Classification tree:
rpart(formula = certified ~ grade + assignment, data = M1, method = "class")

Variables actually used in tree construction:
[1] assignment grade     

Root node error: 275/1000 = 0.275

n= 1000 

CP        nsplit rel error   xerror      xstd

1 0.923636      0  1.000000 1.000000 0.0513455

2 0.058182      1  0.076364 0.076364 0.0164880

3 0.010000      2  0.018182 0.018182 0.0081108 

然后我修剪它:

c.tree2 <- prune(c.tree1, cp = 0.047739)
printcp(c.tree2)

c.tree2结果与c.tree1完全相同:

Classification tree:
rpart(formula = certified ~ grade + assignment, data = M1, method = "class")

Variables actually used in tree construction:
[1] assignment grade     

Root node error: 275/1000 = 0.275

n= 1000 

CP        nsplit rel error   xerror      xstd

1 0.923636      0  1.000000 1.000000 0.0513455

2 0.058182      1  0.076364 0.076364 0.0164880

3 0.010000      2  0.018182 0.018182 0.0081108 

我的意思是,我已经设置了一个CP值,但它仍然随机打印出3个。显然它不是一棵新树。有人可以帮我解决这个问题吗?谢谢!

0 个答案:

没有答案