Description Usage Arguments Details Value Functions
Fit a Naive Bayes Classifier
1 2 3 | naive_bayes(formula, data, nzv_thresh = 1e-06)
log_odds(x, mus, sigmas)
|
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) |
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.
A list with the class n
containing the following:
the original target values
the original model data matrix
the class values
the values of the linear combination
a list of the group means, each item is a vector
the list of the group variances, each item is a vector
the ratio of prior rates
A numeric scalar
log_odds
: Calculate Log odds for normally distributed data (a support function)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.