Description Usage Arguments Details Value Author(s) See Also Examples

Classification based on the Gaussian Naive Bayes model.

1 2 3 |

`object` |
object of class inheriting from |

`newdata` |
matrix with metric predictors (only numeric matrix accepted). |

`type` |
if "class", new data points are classified according to the highest posterior probabilities. If "prob", the posterior probabilities for each class are returned. |

`threshold` |
value by which zero probabilities or probabilities within the epsilon-range corresponding to metric variables are replaced (zero probabilities corresponding to categorical variables can be handled with Laplace (additive) smoothing). |

`eps` |
value that specifies an epsilon-range to replace zero or close to zero probabilities by |

`...` |
not used. |

This is a specialized version of the Naive Bayes classifier, in which all features take on real values and class conditional probabilities are modelled with the Gaussian distribution.

Class posterior probabilities are calculated using the Bayes' rule under the assumption of independence of predictors. If no `newdata`

is provided, the data from the object is used.

The Gaussian Naive Bayes is available in both, `naive_bayes`

and `gaussian_naive_bayes`

. The implementation of the specialized Naive Bayes provides more efficient performance though. The speedup comes from the restricting the data input to a numeric matrix and performing the linear algebra as well vectorized operations on it. In other words, the efficiency comes at cost of the flexibility.

The NAs in the newdata are not included into the calculation of posterior probabilities; and if present an informative warning is given.

The `gaussian_naive_bayes`

function is equivalent to the `naive_bayes`

function with the numeric matrix or a data.frame containing only numeric variables.

`predict.gaussian_naive_bayes`

returns either a factor with class labels corresponding to the maximal conditional posterior probabilities or a matrix with class label specific conditional posterior probabilities.

Michal Majka, michalmajka@hotmail.com

`naive_bayes`

, `gaussian_naive_bayes`

, `plot.gaussian_naive_bayes`

, `tables`

, `get_cond_dist`

, `%class%`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ```
data(iris)
y <- iris[[5]]
M <- as.matrix(iris[-5])
### Train the Gaussian Naive Bayes
gnb <- gaussian_naive_bayes(x = M, y = y)
### Classification
head(predict(gnb, newdata = M, type = "class"))
head(gnb %class% M)
### Posterior probabilities
head(predict(gnb, newdata = M, type = "prob"))
head(gnb %prob% M)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.