Calculates the confusion matrix for a (possibly resampled) prediction. Rows indicate true classes, columns predicted classes. The marginal elements count the number of classification errors for the respective row or column, i.e., the number of errors when you condition on the corresponding true (rows) or predicted (columns) class. The last bottom right element displays the total amount of errors.
A list is returned that contains multiple matrices.
If relative = TRUE
we compute three matrices, one with absolute values and two with relative.
The relative confusion matrices are normalized based on rows and columns respectively,
if FALSE
we only compute the absolute value matrix.
The print
function returns the relative matrices in
a compact way so that both row and column marginals can be seen in one matrix.
For details see ConfusionMatrix.
Note that for resampling no further aggregation is currently performed. All predictions on all test sets are joined to a vector yhat, as are all labels joined to a vector y. Then yhat is simply tabulated vs. y, as if both were computed on a single test set. This probably mainly makes sense when cross-validation is used for resampling.
calculateConfusionMatrix(pred, relative = FALSE, sums = FALSE, set = "both") # S3 method for ConfusionMatrix print(x, both = TRUE, digits = 2, ...)
pred | (Prediction) |
---|---|
relative | ( |
sums | ( |
set | ( |
x | (ConfusionMatrix) |
both | ( |
digits | ( |
... | (any) |
print
:
Other performance:
ConfusionMatrix
,
calculateROCMeasures()
,
estimateRelativeOverfitting()
,
makeCostMeasure()
,
makeCustomResampledMeasure()
,
makeMeasure()
,
measures
,
performance()
,
setAggregation()
,
setMeasurePars()
# get confusion matrix after simple manual prediction allinds = 1:150 train = sample(allinds, 75) test = setdiff(allinds, train) mod = train("classif.lda", iris.task, subset = train) pred = predict(mod, iris.task, subset = test) print(calculateConfusionMatrix(pred))#> predicted #> true setosa versicolor virginica -err.- #> setosa 23 0 0 0 #> versicolor 0 23 1 1 #> virginica 0 0 28 0 #> -err.- 0 0 1 1#> setosa versicolor virginica -err.- -n- #> setosa 23 0 0 0 23 #> versicolor 0 23 1 1 24 #> virginica 0 0 28 0 28 #> -err.- 0 0 1 1 NA #> -n- 23 23 29 NA 75#> Relative confusion matrix (normalized by row/column): #> predicted #> true setosa versicolor virginica -err.- #> setosa 1.00/1.00 0.00/0.00 0.00/0.00 0.00 #> versicolor 0.00/0.00 0.96/1.00 0.04/0.03 0.04 #> virginica 0.00/0.00 0.00/0.00 1.00/0.97 0.00 #> -err.- 0.00 0.00 0.03 0.01 #> #> #> Absolute confusion matrix: #> predicted #> true setosa versicolor virginica -err.- #> setosa 23 0 0 0 #> versicolor 0 23 1 1 #> virginica 0 0 28 0 #> -err.- 0 0 1 1#>#>#>#>#>#>#>#> predicted #> true setosa versicolor virginica -err.- #> setosa 50 0 0 0 #> versicolor 0 47 3 3 #> virginica 0 1 49 1 #> -err.- 0 1 3 4