View source: R/learner_naivebayes.R
| learner_naivebayes | R Documentation |
Constructs a learner class object for fitting a naive bayes
classifier with naivebayes. As shown in the examples, the constructed
learner returns predicted class probabilities of class 2 in case of binary
classification. A n times p matrix, with n being the number of
observations and p the number of classes, is returned for multi-class
classification.
learner_naivebayes(
formula,
info = "Naive Bayes",
laplace.smooth = 0,
kernel = FALSE,
learner.args = NULL,
...
)
formula |
(formula) Formula specifying response and design matrix. |
info |
(character) Optional information to describe the instantiated learner object. |
laplace.smooth |
Laplace smoothing |
kernel |
If TRUE a kernel estimator is used for numeric predictors (otherwise a gaussian model is used) |
learner.args |
(list) Additional arguments to learner$new(). |
... |
Additional arguments to naivebayes. |
learner object.
n <- 5e2
x1 <- rnorm(n, sd = 2)
x2 <- rnorm(n)
y <- rbinom(n, 1, lava::expit(x2*x1 + cos(x1)))
d <- data.frame(y, x1, x2)
# binary classification
lr <- learner_naivebayes(y ~ x1 + x2)
lr$estimate(d)
lr$predict(head(d))
# multi-class classification
lr <- learner_naivebayes(Species ~ .)
lr$estimate(iris)
lr$predict(head(iris))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.