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

Cross-validation for the naive Bayes classifiers | R Documentation |

Cross-validation for the naive Bayes classifiers.

```
nb.cv(x, ina, type = "gaussian", folds = NULL, nfolds = 10,
stratified = TRUE, seed = FALSE, pred.ret = FALSE)
```

`x` |
A matrix with the available data, the predictor variables. |

`ina` |
A vector of data. The response variable, which is categorical (factor is acceptable). |

`type` |
The type of naive Bayes, "gaussian", "gamma", "weibull", "normlog", "laplace", "cauchy", "logitnorm", "beta", "vm" or "spml", "poisson", "multinom", "geom" or "bernoulli". |

`folds` |
A list with the indices of the folds. |

`nfolds` |
The number of folds to be used. This is taken into consideration only if "folds" is NULL. |

`stratified` |
Do you want the folds to be selected using stratified random sampling? This preserves the analogy of the samples of each group. Make this TRUE if you wish. |

`seed` |
If you set this to TRUE, the same folds will be created every time. |

`pred.ret` |
If you want the predicted values returned set this to TRUE. |

A list including:

`preds` |
If pred.ret is TRUE the predicted values for each fold are returned as elements in a list. |

`crit` |
A vector whose length is equal to the number of k and is the accuracy metric for each k. For the classification case it is the percentage of correct classification. If you want to compute other metrics of accuracy we suggest you choose "pred.ret = TRUE" when running the function and then write a simple function to compute more metrics. See . |

Michail Tsagris.

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

Friedman J., Hastie T. and Tibshirani R. (2017). The elements of statistical learning. New York: Springer.

```
weibullnb.pred, weibull.nb, vm.nb, vmnb.pred, mle.lda,
reg.mle.lda, multinom.reg
```

```
x <- as.matrix(iris[, 1:4])
mod <- nb.cv(ina = iris[, 5], x = x )
```

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.