accuracyFromConfusionMatrix3x3: Accuracy based on a predictPair confusion matrix.

Description Usage Arguments Value References See Also Examples

View source: R/performance.R

Description

Given a confusion matrix from pair predict (the output of confusionMatrixFor_Neg1_0_1), calculate an accuracy. By default assumes zeroes are guesses and that half of them are correct. This guessing assumptions helps measures of accuracy converge faster for small samples, but it will artificially reduce the variance of an algorithm's predictions, if that is what you are trying to measure.

Usage

1
accuracyFromConfusionMatrix3x3(confusion_matrix, zero_as_guess = TRUE)

Arguments

confusion_matrix

A 3x3 matrix where rows are correct outcomes (-1, 0, 1) and columns are predicted outcomes (-1, 0, 1).

zero_as_guess

Optional parameter which by default treats the 2nd zero column as guesses and assigns half of them to be correct.

Value

A value from 0 to 1 for the proportion correct.

References

Wikipedia's entry on https://en.wikipedia.org/wiki/Confusion_matrix.

See Also

confusionMatrixFor_Neg1_0_1 for generating the confusion matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Below accuracy is 1 (100% correct) because 4 -1's were correctly predicted,
# and 2 1's were correctly predicted.  (On-diagonal elements are correct
# predictions.)
accuracyFromConfusionMatrix3x3(cbind(c(4,0,0), c(0,0,0), c(0,0,2)))

# 3 wrong and 3 more wrong for 0 accuracy.
accuracyFromConfusionMatrix3x3(cbind(c(0,0,3), c(0,0,0), c(3,0,0)))

# Below is 4 + 5 correct, 1 incorrect, for 9/10 = 0.9 accuracy.
accuracyFromConfusionMatrix3x3(cbind(c(4,0,1), c(0,0,0), c(0,0,5)))

# Below has 3+1=4 guesses, and 0.5 are assigned correct.
accuracyFromConfusionMatrix3x3(cbind(c(0,0,0), c(3,0,1), c(0,0,0)))

Example output

[1] 1
[1] 0
[1] 0.9
[1] 0.5

heuristica documentation built on Sept. 8, 2021, 9:08 a.m.