So I have a decision tree "c.tree1" with 3 different CP values. Now I want to prune it with an exact CP value but the result is the same as "c. tree1" with 3 CP values. Is that weird?
c.tree1 <- rpart(certified ~ grade + assignment,
data = M1, method = "class")
printcp(c.tree1)
The result is:
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
Then I prune it:
c.tree2 <- prune(c.tree1, cp = 0.047739)
printcp(c.tree2)
And c.tree2 result is completely the same with 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
I mean, I've already set a CP value but it still randomly prints 3 out. Obviously it's not a new tree. Can someone help me fix that? Thanks!