2015-11-30 45 views
2

rpart包中,可以得到以下来自printcp功能的输出。但是如何提取根节点的错误值呢?如何从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 

回答

3

你可以从你fit通过的frame成分得到根本错误值:

fit$frame[1, 'dev']/fit$frame[1, 'n'] 

fit$frame第1行中的yval2.V5条目。