# as.table.confusionMatrix: Save Confusion Table Results In caret: Classification and Regression Training

## Description

Conversion functions for class `confusionMatrix`

## Usage

 ```1 2 3 4 5``` ```## 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

## 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

`confusionMatrix`

## 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) ```

### Example output

```Loading required package: lattice
truth
pred       abnormal normal
abnormal      231     32
normal         27     54
abnormal normal
abnormal      231     32
normal         27     54
[,1]
Accuracy       0.8284883721
Kappa          0.5335968379
AccuracyLower  0.7844134380
AccuracyUpper  0.8667985207
AccuracyNull   0.7500000000
AccuracyPValue 0.0003096983
McnemarPValue  0.6025370061
[,1]
Sensitivity          0.8953488
Specificity          0.6279070
Pos Pred Value       0.8783270
Neg Pred Value       0.6666667
Precision            0.8783270
Recall               0.8953488
F1                   0.8867562
Prevalence           0.7500000
Detection Rate       0.6715116
Detection Prevalence 0.7645349
Balanced Accuracy    0.7616279
setosa versicolor virginica
setosa         15         16        19
versicolor     18         16        16
virginica      17         18        15
```

caret documentation built on May 2, 2019, 5:47 p.m.