Database Reference
In-Depth Information
categorical predictor variables using the Bayes rule. The function takes the form of
naiveBayes(formula, data,…) , where the arguments are defined as follows.
formula: A formula of the form class ˜ x1 + x2 + … assuming x1,
x2… are conditionally independent
data: A data frame of factors
Use the following code snippet to execute the model and display the results.
model <- naiveBayes(Enrolls ˜
Age+Income+JobSatisfaction+Desire,
traindata)
# display model
model
The output that follows shows that the probabilities of model match the
probabilities from the previous method. The default laplace=laplace setting
enables the Laplace smoothing.
Naive Bayes Classifier for Discrete Predictors
Call:
naiveBayes.default(x = X, y = Y, laplace = laplace)
A-priori probabilities:
Y No Yes
0.0000000 0.3571429 0.6428571
Conditional probabilities:
Age
Y <=30 >40 31 to 40
No 0.6000000 0.4000000 0.0000000
Yes 0.2222222 0.3333333 0.4444444
Income
Y High Low Medium
No 0.4000000 0.2000000 0.4000000
Yes 0.2222222 0.3333333 0.4444444
JobSatisfaction
Y No Yes
No 0.8000000 0.2000000
Yes 0.3333333 0.6666667
Desire
Y Excellent Fair
Search WWH ::




Custom Search