Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何从决策树计算错误率?_R_Classification_Decision Tree_Rpart - Fatal编程技术网

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

有人知道如何用R计算决策树的错误率吗?
我正在使用
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
  • 0.82353 x 0.20988=0.1728425(17.2%)是交叉验证的错误率(使用10倍CV,请参见
    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