天天看点

分类分析--选择预测效果最好的解

分类分析--选择预测效果最好的解

预测准确性度量

分类分析--选择预测效果最好的解

下面给出计算这几个统计量的函数:

评估二分类准确性:

performance <- function(table, n=2){

 if(!all(dim(table) == c(2,2)))

stop("Must be a 2 x 2 table")

(1)第一步:得到频数

tn = table[1,1]

 fp = table[1,2]

 fn = table[2,1]

 tp = table[2,2]

(2)第二步:计算统计量

 sensitivity = tp/(tp+fn)

 specificity = tn/(tn+fp)

 ppp = tp/(tp+fp)

 npp = tn/(tn+fn)

 hitrate = (tp+tn)/(tp+tn+fp+fn)

(3)第三步:输出结果

 result <- paste("Sensitivity = ", round(sensitivity, n) ,

 "\nSpecificity = ", round(specificity, n),

 "\nPositive Predictive Value = ", round(ppp, n),

 "\nNegative Predictive Value = ", round(npp, n),

 "\nAccuracy = ", round(hitrate, n), "\n", sep="")

 cat(result)

}

以下代码清单将performance()函数用于上述提到的五个分类器:

逻辑回归

分类分析--选择预测效果最好的解

传统决策树

分类分析--选择预测效果最好的解

条件推断树

分类分析--选择预测效果最好的解

随机森林(决策树)

分类分析--选择预测效果最好的解

随机森林(条件推断树)

分类分析--选择预测效果最好的解

支持向量机(无调和参数)

分类分析--选择预测效果最好的解

支持向量机(有调和参数)

分类分析--选择预测效果最好的解

作者:zhang-X​,转载请注明原文链接

继续阅读