topepo / caret

caret (Classification And Regression Training) R package that contains misc functions for training and plotting classification and regression models
http://topepo.github.io/caret/index.html
1.61k stars 634 forks source link

(maybe) the argument confusionMatrix() wrong #1356

Closed gosmah closed 6 months ago

gosmah commented 6 months ago

Hello, i think the confusionMatrix() have wrong formula or argument.

dat2 <- 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))) dat2 real pred 1 1 1 2 1 1 3 1 0 4 0 1 5 0 0 6 1 1 7 1 1 8 1 1 9 1 0

the precision of class "0" should be TP÷(TP+FP) right? so it should be 1÷(1+1)=0.5 but when i run using confusionMatrix() command the precision become like this below

image

i follow it like the guide confusionMatrix(data =....., reference=.....,) where data is predictive & reference is true result. maybe some formula wrong or maybe the table made by confusionMatrix() command is wrong by swapping the FP & FN value

Please let me know it i wrong or right