Learn R Programming

bnclassify (version 0.4.8)

predict.bnc_fit: Predicts class labels or class posterior probability distributions.

Description

Predicts class labels or class posterior probability distributions.

Usage

# S3 method for bnc_fit
predict(object, newdata, prob = FALSE, ...)

Value

If prob=FALSE, then returns a length-\(N\) factor with the same levels as the class variable in x, where \(N\) is the number of rows in newdata. Each element is the most likely class for the corresponding row in newdata. If prob=TRUE, returns a \(N\) by \(C\) numeric matrix, where \(C\) is the number of classes; each row corresponds to the class posterior of the instance.

Arguments

object

A bnc_bn object.

newdata

A data frame containing observations whose class has to be predicted.

prob

A logical. Whether class posterior probability should be returned.

...

Ignored.

Details

Ties are resolved randomly. Inference is much slower if newdata contains NAs.

Examples

Run this code
data(car)
nb <- bnc('nb', 'class', car, smooth = 1)
p <- predict(nb, car)
head(p)
p <- predict(nb, car, prob = TRUE)
head(p)

Run the code above in your browser using DataLab