如何从rpart printcp函数获取根节点错误值?

时间:2015-11-30 08:59:42

标签: r rpart

rpart包中,可以从printcp函数获得以下输出。但是如何提取根节点错误值?

Classification tree:
rpart(formula = survived ~ ., data = ptitanic, control = rpart.control(cp = 1e-04))

#Variables actually used in tree construction:
#[1] age    parch  pclass sex    sibsp 

#Root node error: 500/1309 = 0.38

#n= 1309 

 #     CP nsplit rel error xerror  xstd
 #1 0.4240      0      1.00   1.00 0.035
 #2 0.0210      1      0.58   0.58 0.030
 #3 0.0150      3      0.53   0.57 0.030
 #4 0.0113      5      0.50   0.57 0.030
 #5 0.0026      9      0.46   0.53 0.029
 #6 0.0020     16      0.44   0.53 0.029
 #7 0.0001     18      0.44   0.53 0.029

1 个答案:

答案 0 :(得分:3)

您可以通过frame的{​​{1}}组件获取根错误值:

fit

fit$frame[1, 'dev']/fit$frame[1, 'n'] 第一行中的yval2.V5条目。

相关问题