# confusionMatrix

From caret v2.27
by Max Kuhn

##### Create a confusion matrix

Calculates a cross-tabulation of observed and predicted classes with associated statistics.

- Keywords
- utilities

##### Usage

```
## S3 method for class 'default':
confusionMatrix(data, reference, positive = NULL, dnn = c("Prediction", "Reference"), ...)
```

##### Arguments

- data
- a factor of predicted classes
- reference
- a factor of classes to be used as the true results
- positive
- an optional character string for the factor level that corresponds to a "positive" result (if that makes sense for your data). If there are only two factor levels, the first level will be used as the "positive" result.
- dnn
- a character vector of dimnames for the table
- ...
- options to be passed to
`table`

. NOTE: do not include`dnn`

here

##### Details

The functions requires that the factors have exactly the same levels.

For two class problems, the sensitivity, specificity, positive
predictive value and negative predictive value is calculated using the
`positive`

argument. For more than two classes, these results are
calculated comparing each factor level to the remaining levels
(i.e. a "one versus all" approach). In each case, the overall accuracy and Kappa statistic are calculated.

##### Value

- a list with elements
table the results of `table`

on`data`

and`reference`

positive the positive result level overall a numeric vector with overall accuracy and Kappa statistic values byClass the sensitivity, specificity, positive predictive value and negative predictive value for each class. For two class systems, this is calculated once using the `positive`

argument

##### See Also

`sensitivity`

, `specificity`

, `posPredValue`

, `negPredValue`

, `print.confusionMatrix`

##### Examples

```
numLlvs <- 4
confusionMatrix(
factor(sample(rep(letters[1:numLlvs], 200), 50)),
factor(sample(rep(letters[1:numLlvs], 200), 50)))
numLlvs <- 2
confusionMatrix(
factor(sample(rep(letters[1:numLlvs], 200), 50)),
factor(sample(rep(letters[1:numLlvs], 200), 50)))
```

*Documentation reproduced from package caret, version 2.27, License: GPL 2.0*

### Community examples

Looks like there are no examples yet.