小编men*_*ndy的帖子

插入符混淆矩阵的措施有错吗?

我创建了一个函数来根据混淆矩阵计算灵敏度和特异性,后来才发现该caret包有一个confusionMatrix(). 当我尝试时,事情变得非常混乱,因为它似乎caret使用了错误的公式?

示例数据:

dat <- data.frame(real = as.factor(c(1,1,1,0,0,1,1,1,1)),
                  pred = as.factor(c(1,1,0,1,0,1,1,1,0)))
cm <- table(dat$real, dat$pred)
cm
    0 1
  0 1 1
  1 2 5
Run Code Online (Sandbox Code Playgroud)

我的功能:

model_metrics <- function(cm){
  acc <- (cm[1] + cm[4]) / sum(cm[1:4])
  # accuracy = ratio of the correctly labeled subjects to the whole pool of subjects = (TP+TN)/(TP+FP+FN+TN)
  sens <- cm[4] / (cm[4] + cm[3])
  # sensitivity/recall = ratio of the correctly +ve labeled to all who are +ve in …
Run Code Online (Sandbox Code Playgroud)

r machine-learning confusion-matrix r-caret

3
推荐指数
1
解决办法
1911
查看次数

标签 统计

confusion-matrix ×1

machine-learning ×1

r ×1

r-caret ×1