prob2class: Convert a matrix of probabilities to a vector of classes

Description Usage Arguments Value See Also Examples

View source: R/Util.R

Description

Some model types and packages, when asked to predict new values, return the probability that a given class will occur. This function converts this format into a vector of classes (type factor).

Usage

1
prob2class(prob, classes = colnames(prob), threshold = 0)

Arguments

prob

a matrix of probabilities with each column representing a different class.

classes

(optional) the classes represented by prob. Must match the number of columns in prob.

threshold

(optional) if the probability is less than this value, output 0 for that point as we don't have confidence in the result.

Value

A factor variable containing the most probable class indicated by the probability table. Note that if this function is passed a matrix with only one column or a vector of values, it will return a vector of the values. Care should be taken as this function does not always return the same type.

See Also

isCat, isCont, and factorValue for help in handling the result.

Examples

1
2
3
4
5
6
7
8
9
data ('siteData')
modelRun <- generateModels (data = siteData,
                            modelTypes = suppModels,
                            x = c('brtns','grnns','wetns','dem','slp','asp','hsd'),
                            y = 'ecoType',
                            grouping = ecoGroup[['domSpecies','transform']])
m <- modelRun$gbm
p <- buildPredict(m)(m, getData(m))
prob2class(p)

henkelstone/NPEL.Classification documentation built on May 17, 2019, 3:42 p.m.