Database Reference
In-Depth Information
No 0.6000000 0.4000000
Yes 0.3333333 0.6666667
Next, predicting the outcome of Enrolls with the testdata shows the result is
Enrolls =Yes .
# predict with testdata
results <- predict (model,testdata)
# display results
results
[1] Yes
Levels: No Yes
The naiveBayes function accepts a Laplace parameter that allows the
customization of the value of Equation 7.17 for the Laplace smoothing. The code
that follows shows how to build a naïve Bayes classifier with Laplace smoothing
for prediction.
# use the NB classifier with Laplace smoothing
model1 = naiveBayes(Enrolls ˜., traindata, laplace=.01)
# display model
model1
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
0.333333333 0.333333333 0.333333333
No 0.598409543 0.399602386 0.001988072
Yes 0.222591362 0.333333333 0.444075305
Income
Y High Low Medium
0.3333333 0.3333333 0.3333333
No 0.3996024 0.2007952 0.3996024
Search WWH ::




Custom Search