classError: Classification error

Description Usage Arguments Details Value See Also Examples

View source: R/util.R

Description

Computes the errore rate of a given classification relative to the known classes, and the location of misclassified data points.

Usage

1
classError(classification, class)

Arguments

classification

A numeric, character vector or factor specifying the predicted class labels. Must have the same length as class.

class

A numeric, character vector or factor of known true class labels. Must have the same length as classification.

Details

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.

Value

A list with the following two components:

misclassified

The indexes of the misclassified data points in a minimum error mapping between the predicted classification and the known true classes.

errorRate

The error rate corresponding to a minimum error mapping between the predicted classification and the known true classes.

See Also

map mapClass, table

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
(a <- rep(1:3, 3))
(b <- rep(c("A", "B", "C"), 3))
classError(a, b)

(a <- sample(1:3, 9, replace = TRUE))
(b <- sample(c("A", "B", "C"), 9, replace = TRUE))
classError(a, b)

class <- factor(c(5,5,5,2,5,3,1,2,1,1), levels = 1:5)
probs <- matrix(c(0.15, 0.01, 0.08, 0.23, 0.01, 0.23, 0.59, 0.02, 0.38, 0.45, 
                  0.36, 0.05, 0.30, 0.46, 0.15, 0.13, 0.06, 0.19, 0.27, 0.17, 
                  0.40, 0.34, 0.18, 0.04, 0.47, 0.34, 0.32, 0.01, 0.03, 0.11, 
                  0.04, 0.04, 0.09, 0.05, 0.28, 0.27, 0.02, 0.03, 0.12, 0.25, 
                  0.05, 0.56, 0.35, 0.22, 0.09, 0.03, 0.01, 0.75, 0.20, 0.02),
                nrow = 10, ncol = 5)
cbind(class, probs, map = map(probs))
classError(map(probs), class)

Example output

Package 'mclust' version 5.4.3
Type 'citation("mclust")' for citing this R package in publications.
[1] 1 2 3 1 2 3 1 2 3
[1] "A" "B" "C" "A" "B" "C" "A" "B" "C"
$misclassified
integer(0)

$errorRate
[1] 0

[1] 1 2 3 1 2 3 3 2 2
[1] "B" "C" "A" "A" "C" "C" "A" "B" "B"
$misclassified
[1] 1 2 5 6

$errorRate
[1] 0.4444444

      class                          map
 [1,]     5 0.15 0.36 0.40 0.04 0.05   3
 [2,]     5 0.01 0.05 0.34 0.04 0.56   5
 [3,]     5 0.08 0.30 0.18 0.09 0.35   5
 [4,]     2 0.23 0.46 0.04 0.05 0.22   2
 [5,]     5 0.01 0.15 0.47 0.28 0.09   3
 [6,]     3 0.23 0.13 0.34 0.27 0.03   3
 [7,]     1 0.59 0.06 0.32 0.02 0.01   1
 [8,]     2 0.02 0.19 0.01 0.03 0.75   5
 [9,]     1 0.38 0.27 0.03 0.12 0.20   1
[10,]     1 0.45 0.17 0.11 0.25 0.02   1
$misclassified
[1] 2 3 8

$errorRate
[1] 0.3

mclust documentation built on Nov. 5, 2021, 5:07 p.m.