Classifying data with the Naïve Bayes classifier
The Naïve Bayes classifier is also a probability-based classifier, which is based on applying the Bayes theorem with a strong independent assumption. In this recipe, we will introduce how to classify data with the Naïve Bayes classifier.
Getting ready
You need to have the first recipe completed by generating training and testing datasets.
How to do it...
Perform the following steps to classify the churn data with the Naïve Bayes classifier:
- Load the
e1071
library and employ thenaiveBayes
function to build the classifier:> library(e1071) > classifier=naiveBayes(trainset[, !names(trainset) %in% c("churn")], trainset$churn)
- Type
classifier
to examine the function call, a-priori probability, and conditional ...
Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.