2
$\begingroup$

true <- c(1,1,1,2,3,3)
pred <- c(1,1,1,2,2,2)

library(mclust)

classError(true, pred)

The outputs are misclassified 4 and error rate 0.16667.

I don't know how it gives 0.16667 error rate

$\endgroup$

1 Answer 1

3
$\begingroup$

The documentation of mclust::classError explains that

If more than one mapping between predicted classification and the known truth corresponds to the minimum number of classification errors, only one possible set of misclassified observations is returned.

The minimum error mapping between pred and true is 1 ⇔ 1, 2 ⇔ 3 (and the true 2 is misclassified).

true <- c(1, 1, 1, 2, 3, 3)
pred <- c(1, 1, 1, 2, 2, 2)

mclust::classError(true, pred)
#> $misclassified
#> [1] 4
#> 
#> $errorRate
#> [1] 0.1666667

Specify the possible labels explicitly to get the expected result of 2 errors out 6 data points.

pred2 <- factor(pred, levels = 1:3)
true2 <- factor(true, levels = 1:3)

mclust::classError(true2, pred2)
#> $misclassified
#> [1] 5 6
#> 
#> $errorRate
#> [1] 0.3333333
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.