caret (version 5.17-7)

confusionMatrix.train: Estimate a Resampled Confusion Matrix

Description

Using a train, rfe, sbf object, determine a confusion matrix based on the resampling procedure

Usage

## S3 method for class 'train':
confusionMatrix(data, norm = "overall", 
                dnn = c("Prediction", "Reference"), ...)

## S3 method for class 'rfe': confusionMatrix(data, norm = "overall", dnn = c("Prediction", "Reference"), ...)

## S3 method for class 'sbf': confusionMatrix(data, norm = "overall", dnn = c("Prediction", "Reference"), ...)

Arguments

data
an object of class train, rfe, sbf that did not use out-of-bag resampling or leave-one-out cross-validation.
norm
a character string indicating how the table entries should be normalized. Valid values are "none", "overall" or "average".
dnn
a character vector of dimnames for the table
...
not used here

Value

  • a list of class confusionMatrix.train, confusionMatrix.rfe or confusionMatrix.sbf with elements
  • tablethe normalized matrix
  • norman echo fo the call
  • texta character string with details about the resampling procedure (e.g. "Bootstrapped (25 reps) Confusion Matrix"

Details

When train is used for tuning a model, it tracks the confusion matrix cell entries for the hold-out samples. These can be aggregated and used for diagnostic purposes. For train, the matrix is estimated for the final model tuning parameters determined by train. For rfe, the matrix is associated with the optimal number of variables.

There are several ways to show the table entries. Using norm = "none" will show the frequencies of samples on each of the cells (across all resamples). norm = "overall" first divides the cell entries by the total number of data points in the table, then averages these percentages. norm = "average" takes the raw, aggregate cell counts across resamples and divides by the number of resamples (i.e. to yield an average count for each cell).

See Also

confusionMatrix, train, rfe, sbf, trainControl

Examples

Run this code
data(iris)
TrainData <- iris[,1:4]
TrainClasses <- iris[,5]

knnFit <- train(TrainData, TrainClasses,
                method = "knn",
                preProcess = c("center", "scale"),
                tuneLength = 10,
                trControl = trainControl(method = "cv"))
confusionMatrix(knnFit)
confusionMatrix(knnFit, "average")
confusionMatrix(knnFit, "none")

Run the code above in your browser using DataCamp Workspace