naive_bayes: Fit a Naive Bayes Classifier

Description Usage Arguments Details Value Functions

Description

Fit a Naive Bayes Classifier

Usage

1
2
3
naive_bayes(formula, data, nzv_thresh = 1e-06)

log_odds(x, mus, sigmas)

Arguments

formula

An R formual specifying the Naive Bayes Classifier

data

A data frame to fit the model

x

the data

mus

the group means (as vectors)

sigmas

the group varainces (as vectors)

Details

This version of a naive bayes classifier generates predictions through the log odds of an observation belonging to either class 1 or 0. We can the classifier "naive" because we calculate the odds assuming that each column is independent.

Our classification rule follows:

f(x) = 1 \mathrm{ if } \log \frac{P(Y = 1 | X = x)}{P(Y = 0 | X = x)}

= \log \frac{p_1}{p_0} + ∑_{j = 1}^{p} ≤ft[ \frac{1}{2} \log \frac{σ_{0j}^2}{σ_{1j}^2} - \frac{(x_j - μ_{1j})^2}{2 σ_{1j}^2} + \frac{(x_j - μ_{0j})^2}{2 σ_{0j}^2}\right]

The log_odds function makes it much easier to apply this formula across the entire data frame.

Value

A list with the class n containing the following:

actual

the original target values

x

the original model data matrix

fit

the class values

preds

the values of the linear combination

mus

a list of the group means, each item is a vector

sigmas

the list of the group variances, each item is a vector

p_rat

the ratio of prior rates

A numeric scalar

Functions


michaelquinn32/adventureR documentation built on May 22, 2019, 9:52 p.m.