as.matrix.confusionMatrix: Confusion matrix as a table

Description Usage Arguments Details Value Author(s) Examples

View source: R/confusionMatrix.R

Description

Conversion functions for class confusionMatrix

Usage

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

Arguments

x

an object of class confusionMatrix

what

data to convert to matrix. Either "xtabs", "overall" or "classes"

...

not currently used

Details

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

Value

A matrix or table

Author(s)

Max Kuhn

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
###################
## 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

xtab <- confusionMatrix(iris$Species, sample(iris$Species))
as.matrix(xtab)

caret documentation built on May 2, 2019, 5:39 a.m.