To add to FJCC's answer, when you apply confusionMatrix on a object of class train, it uses confusionMatrix.train, which is by default confusionMatrix(data, norm = "overall", dnn = c("Prediction", "Reference"), ...).
If you want to get the absolute values as FJCC showed in the above post, use norm = "none". Here's an excerpt from the documentation:
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 below:
library(caret)
#> Loading required package: lattice
#> Loading required package: ggplot2
library(e1071)
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, "none")
#> Cross-Validated (10 fold) Confusion Matrix
#>
#> (entries are un-normalized aggregated counts)
#>
#> Reference
#> Prediction setosa versicolor virginica
#> setosa 50 0 0
#> versicolor 0 48 3
#> virginica 0 2 47
#>
#> Accuracy (average) : 0.9667
Created on 2019-05-05 by the reprex package (v0.2.1)
Hope this helps.