View source: R/naive.bayes.classifiers.R

Naive Bayes classifier for binary (Bernoulli) data | R Documentation |

Naive Bayes classifier for binary (Bernoulli) data.

```
bernoulli.nb(xnew = NULL, x, ina)
```

`xnew` |
A numerical matrix with new predictor variables whose group is to be predicted. Each column contains binary (0 or 1) data. |

`x` |
A numerical matrix with observed predictor variables. Each column contains binary (0 or 1) data. |

`ina` |
A numerical vector with strictly positive numbers, i.e. 1,2,3 indicating the groups of the dataset. Alternatively this can be a factor variable. |

Each column is supposed to contain binary data. Thus, for each column a Berboulli distributions is fitted. The product of the densities is the joint multivariate distribution.

A list including:

`pi` |
A matrix with the estimated probabilities of each group and variable. |

`ni` |
The sample size of each group in the dataset. |

`est` |
The estimated group of the xnew observations. It returns a numerical value back regardless of the target variable being numerical as well or factor. Hence, it is suggested that you do \"as.numeric(ina)\" in order to see what is the predicted class of the new data. |

Michail Tsagris.

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.

` bernoullinb.pred, nb.cv `

```
x <- matrix( rbinom(50 * 4, 1, 0.5), ncol = 4 )
ina <- rbinom(50, 1, 0.5) + 1
a <- bernoulli.nb(x, x, ina)
```

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.