R confusionMatrix()

1 개요[ | ]

R confusionMatrix()

2 전체 정보 조회[ | ]

R
CPU
3.1s
MEM
206M
3.4s
Copy
library(caret) # confusionMatrix()
t <- as.table(rbind(c(231, 32), c(27, 54)))
dimnames(t) <- list(pred = c("abnormal", "normal"), truth = c("abnormal", "normal"))
confusionMatrix(t)
Loading required package: lattice
Loading required package: ggplot2
Confusion Matrix and Statistics

          truth
pred       abnormal normal
  abnormal      231     32
  normal         27     54
                                          
               Accuracy : 0.8285          
                 95% CI : (0.7844, 0.8668)
    No Information Rate : 0.75            
    P-Value [Acc > NIR] : 0.0003097       
                                          
                  Kappa : 0.5336          
                                          
 Mcnemar's Test P-Value : 0.6025370       
                                          
            Sensitivity : 0.8953          
            Specificity : 0.6279          
         Pos Pred Value : 0.8783          
         Neg Pred Value : 0.6667          
             Prevalence : 0.7500          
         Detection Rate : 0.6715          
   Detection Prevalence : 0.7645          
      Balanced Accuracy : 0.7616          
                                          
       'Positive' Class : abnormal        
                                          

R
Copy
library(caret) # confusionMatrix()
lvs <- c("normal", "abnormal")
truth <- factor(rep(lvs, times = c(86, 258)), levels = rev(lvs))
pred <- factor(
  c(rep(lvs, times = c(54, 32)), rep(lvs, times = c(27, 231))),               
  levels = rev(lvs))
confusionMatrix(pred, truth)
Loading
R
Copy
library(caret) # confusionMatrix()
lvs <- c("normal", "abnormal")
truth <- factor(rep(lvs, times = c(86, 258)), levels = rev(lvs))
pred <- factor(
  c(rep(lvs, times = c(54, 32)), rep(lvs, times = c(27, 231))),               
  levels = rev(lvs))
xtab <- table(pred, truth)
confusionMatrix(xtab)
Loading

3 특정값만 추출 ★[ | ]

R
Copy
library(caret) # confusionMatrix()
t <- as.table(rbind(c(231, 32), c(27, 54)))
dimnames(t) <- list(pred = c("abnormal", "normal"), truth = c("abnormal", "normal"))
cm <- confusionMatrix(t)
cm$overall["Accuracy"]
cm$byClass["Sensitivity"]
cm$byClass["Specificity"]
cm$byClass["Specificity"]
cm$byClass["Precision"]
cm$byClass["Recall"]
Loading

4 같이 보기[ | ]

5 참고[ | ]