所以我有一个具有 3 个不同 CP 值的决策树“c.tree1”。现在我想用精确的 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。显然这不是一棵新树。有人可以帮我解决这个问题吗?谢谢!