Categories &

Functions List

Class Definition: CompactClassificationNaiveBayes

statistics: CompactClassificationNaiveBayes

Compact naive Bayes classification

A CompactClassificationNaiveBayes object carries the fitted densities of a ClassificationNaiveBayes model and everything predict needs, but not the observations the model was fitted on. It classifies new data identically to the model it came from, and is far smaller to keep or to ship.

Create one with the compact method of a ClassificationNaiveBayes object. Because it holds no training data, it has no resub methods and cannot be cross-validated.

See also: ClassificationNaiveBayes, fitcnb

Source Code: CompactClassificationNaiveBayes

The CompactClassificationNaiveBayes class contains the following properties:

A cell array of character vectors with one entry per predictor, naming the distribution fitted to it. This property is read-only.

The means used to center the predictors, when the model standardizes them, and empty otherwise. This property is read-only.

The standard deviations used to scale the predictors, when the model standardizes them, and empty otherwise. This property is read-only.

A cell array with one row per class and one column per predictor, holding the parameters fitted to each. This property is read-only.

A cell array with one entry per predictor, holding the distinct levels of each categorical predictor and empty for every other. This property is read-only.

A cell array naming the smoothing kernel of each kernel predictor, and empty for every other. This property is read-only.

A cell array giving the support of each kernel predictor’s density, and empty for every other. This property is read-only.

A numeric matrix with one row per class and one column per predictor, and empty when no predictor uses a kernel density. This property is read-only.

The distinct classes the model was fitted on, in the order the other per-class properties use. This property is read-only.

A numeric row vector with one entry per class, in the order of ClassNames, summing to one.

A square numeric matrix where Cost(i,j) is the cost of classifying an observation of class i into class j.

A character vector naming the function applied to the posterior returned by predict, or a function handle.

A cell array of character vectors naming the predictors. This property is read-only.

The column indices treated as categorical, or empty when none is. This property is read-only.

A character vector naming the response variable. This property is read-only.

A cell array of character vectors naming the predictors as the model sees them. This property is read-only.

The CompactClassificationNaiveBayes class offers the following public methods:

CompactClassificationNaiveBayes: label = predict (obj, XC)

CompactClassificationNaiveBayes: [label, score, cost] = predict (obj, XC)

The same classification the model it came from would give: the label of least expected cost, the posterior of each class, and the expected misclassification cost of each.

The new data may be a table, whose variables are matched to the predictors the model was fitted on by name and not by position: one the model was not fitted on is passed over, one it needs and cannot find is named, and a value holding a level is coded as that level was coded at fitting.

CompactClassificationNaiveBayes: m = margin (obj, X, Y)

CompactClassificationNaiveBayes: m = margin (obj, Tbl, ResponseVarName)

CompactClassificationNaiveBayes: m = margin (obj, Tbl)

X may also be a table Tbl, whose variables are matched to the predictors the model was fitted on by name and not by position. margin (obj, Tbl, ResponseVarName) takes the response from the variable ResponseVarName names, and margin (obj, Tbl) from the variable the model was fitted on. The response may also be given beside the table as Y.

CompactClassificationNaiveBayes: e = edge (obj, X, Y)

CompactClassificationNaiveBayes: e = edge (…, 'Weights', w)

CompactClassificationNaiveBayes: e = edge (obj, Tbl, ResponseVarName)

CompactClassificationNaiveBayes: e = edge (obj, Tbl)

CompactClassificationNaiveBayes: l = loss (obj, X, Y)

CompactClassificationNaiveBayes: l = loss (obj, Tbl, ResponseVarName)

CompactClassificationNaiveBayes: l = loss (obj, Tbl)

CompactClassificationNaiveBayes: l = loss (…, name, value)

Takes the 'LossFun' and 'Weights' options that ClassificationNaiveBayes.loss takes.

X may also be a table Tbl, whose variables are matched to the predictors the model was fitted on by name and not by position. loss (obj, Tbl, ResponseVarName) takes the response from the variable ResponseVarName names, and loss (obj, Tbl) from the variable the model was fitted on. The response may also be given beside the table as Y.

CompactClassificationNaiveBayes: lp = logp (obj, X)

lp = logp (obj, X) returns one value per observation, the logarithm of its density under the fitted model taken over all the classes, each weighted by its prior. A markedly low value marks an observation the model finds unlike anything it was trained on, whatever class it would be assigned to.

X may also be a table, whose variables are matched to the predictors the model was fitted on by name and not by position: one the model was not fitted on is passed over, one it needs and cannot find is named, and a value holding a level is coded as that level was coded at fitting.

CompactClassificationNaiveBayes: savemodel (obj, filename)

savemodel (obj, filename) saves each property of a CompactClassificationNaiveBayes object into an Octave binary file, the name of which is specified in filename, along with an extra variable, which defines the type classification object these variables constitute. Use loadmodel in order to load a classification object into Octave’s workspace.

See also: loadmodel, fitcnb, CompactClassificationNaiveBayes