get.confusion_matrix: Create confusion table and calculate the Balanced Error Rate

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/get.confusion_matrix.R

Description

Create confusion table between a vector of true classes and a vector of predicted classes, calculate the Balanced Error rate

Usage

1
2
3
get.confusion_matrix(truth, all.levels, predicted)

get.BER(confusion)

Arguments

truth

A factor vector indicating the true classes of the samples (typically Y from the training set).

all.levels

Levels of the 'truth' factor. Optional parameter if there are some missing levels in truth compared to the fitted predicted model

predicted

Vector of predicted classes (typically the prediction from the test set). Can contain NA.

confusion

result from a get.confusion_matrix to calculate the Balanced Error Rate

Details

BER is appropriate in case of an unbalanced number of samples per class as it calculates the average proportion of wrongly classified samples in each class, weighted by the number of samples in each class. BER is less biased towards majority classes during the performance assessment.

Value

get.confusion_matrix returns a confusion matrix.

get.BER returns the BER from a confusion matrix

Author(s)

Florian Rohart

References

mixOmics article:

Rohart F, Gautier B, Singh A, LĂȘ Cao K-A. mixOmics: an R package for 'omics feature selection and multiple data integration. PLoS Comput Biol 13(11): e1005752

See Also

predict.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Example
# -----------------------------------
## Not run: 

data(liver.toxicity)
X <- liver.toxicity$gene
Y <- as.factor(liver.toxicity$treatment[, 4])

## if training is perfomed on 4/5th of the original data
samp <- sample(1:5, nrow(X), replace = TRUE)
test <- which(samp == 1)   # testing on the first fold
train <- setdiff(1:nrow(X), test)

plsda.train <- plsda(X[train, ], Y[train], ncomp = 2)
test.predict <- predict(plsda.train, X[test, ], dist = "max.dist")
Prediction <- test.predict$class$max.dist[, 2]

# the confusion table compares the real subtypes with the predicted subtypes for a 2 component model
confusion.mat = get.confusion_matrix(truth = Y[test],
predicted = Prediction)

get.BER(confusion.mat)

## End(Not run)

mixOmics documentation built on June 1, 2018, 5:06 p.m.