###################
## 2 class example
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)
confusionMatrix(pred, truth)
confusionMatrix(xtab, prevalence = 0.25)
###################
## 3 class example
library(MASS)
fit <- lda(Species ~ ., data = iris)
model <- predict(fit)$class
irisTabs <- table(model, iris$Species)
confusionMatrix(irisTabs)
confusionMatrix(model, iris$Species)
newPrior <- c(.05, .8, .15)
names(newPrior) <- levels(iris$Species)
confusionMatrix(irisTabs, prevalence = newPrior)
## Need names for prevalence
confusionMatrix(irisTabs, prevalence = c(.05, .8, .15))
Run the code above in your browser using DataLab