R 如何从决策树计算错误率?
有人知道如何用R计算决策树的错误率吗?R 如何从决策树计算错误率?,r,classification,decision-tree,rpart,R,Classification,Decision Tree,Rpart,有人知道如何用R计算决策树的错误率吗? 我正在使用rpart()函数。假设您的意思是计算用于拟合模型的样本的错误率,您可以使用printcp()。例如,使用在线示例 > library(rpart) > fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis) > printcp(fit) Classification tree: rpart(formula = Kyphosis ~ Age + Numbe
我正在使用
rpart()
函数。假设您的意思是计算用于拟合模型的样本的错误率,您可以使用printcp()
。例如,使用在线示例
> library(rpart)
> fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
> printcp(fit)
Classification tree:
rpart(formula = Kyphosis ~ Age + Number + Start, data = kyphosis)
Variables actually used in tree construction:
[1] Age Start
Root node error: 17/81 = 0.20988
n= 81
CP nsplit rel error xerror xstd
1 0.176471 0 1.00000 1.00000 0.21559
2 0.019608 1 0.82353 0.82353 0.20018
3 0.010000 4 0.76471 0.82353 0.20018
rpart.control()
中的xval
;但也请参见xpred.rpart()
和plotcp()
,它们依赖于这种测量)。这是一个更客观的预测准确性指标树中的分类精度一致:
> library(tree)
> summary(tree(Kyphosis ~ Age + Number + Start, data=kyphosis))
Classification tree:
tree(formula = Kyphosis ~ Age + Number + Start, data = kyphosis)
Number of terminal nodes: 10
Residual mean deviance: 0.5809 = 41.24 / 71
Misclassification error rate: 0.1235 = 10 / 81
其中,误分类错误率
是根据训练样本计算的
> library(tree)
> summary(tree(Kyphosis ~ Age + Number + Start, data=kyphosis))
Classification tree:
tree(formula = Kyphosis ~ Age + Number + Start, data = kyphosis)
Number of terminal nodes: 10
Residual mean deviance: 0.5809 = 41.24 / 71
Misclassification error rate: 0.1235 = 10 / 81