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

# S3 method for train
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

table

the normalized matrix

norm

an echo fo the call

text

a 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 aggregated counts of samples on each of the cells (across all resamples). For norm = "average", the average number of cell counts across resamples is computed (this can help evaluate how many holdout samples there were on average). The default is norm = "overall", which is equivalento to "average" but in percentages.

See also

Examples

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)
#> Cross-Validated (10 fold) Confusion Matrix #> #> (entries are percentual average cell counts across resamples) #> #> Reference #> Prediction setosa versicolor virginica #> setosa 33.3 0.0 0.0 #> versicolor 0.0 32.7 2.0 #> virginica 0.0 0.7 31.3 #> #> Accuracy (average) : 0.9733 #>
confusionMatrix(knnFit, "average")
#> Cross-Validated (10 fold) Confusion Matrix #> #> (entries are average cell counts across resamples) #> #> Reference #> Prediction setosa versicolor virginica #> setosa 5.0 0.0 0.0 #> versicolor 0.0 4.9 0.3 #> virginica 0.0 0.1 4.7 #> #> Accuracy (average) : 0.9733 #>
confusionMatrix(knnFit, "none")
#> Cross-Validated (10 fold) Confusion Matrix #> #> (entries are un-normalized aggregated counts) #> #> Reference #> Prediction setosa versicolor virginica #> setosa 50 0 0 #> versicolor 0 49 3 #> virginica 0 1 47 #> #> Accuracy (average) : 0.9733 #>