Learn R Programming

caret (version 5.12-04)

as.table.confusionMatrix: Save Confusion Table Results

Description

Conversion functions for class confusionMatrix

Usage

## S3 method for class 'confusionMatrix':
as.matrix(x, what = "xtabs", ...)

## S3 method for class 'confusionMatrix': as.table(x, ...)

Arguments

x
an object of class confusionMatrix
what
data to conver to matrix. Either "xtabs", "overall" or "classes"
...
not currently used

Value

  • A matrix or table

Details

For as.table, the cross-tabulations are saved. For as.matrix, the three object types are saved in matrix format.

See Also

confusionMatrix

Examples

Run this code
###################
## 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)

results <- confusionMatrix(xtab)
as.table(results)
as.matrix(results)
as.matrix(results, what = "overall")
as.matrix(results, what = "classes")
  
###################
## 3 class example

library(MASS)

fit <- lda(Species ~ ., data = iris)
model <- predict(fit)$class

irisTabs <- table(model, iris$Species)

results <- confusionMatrix(irisTabs)
as.table(results)
as.matrix(results)
as.matrix(results, what = "overall")
as.matrix(results, what = "classes")

Run the code above in your browser using DataLab