O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Naïve Bayes assumes that all features are independent and equally important; that is, the effect of a predictor (x) to class (c) is independent of the effect of other predictors to class (c). Besides being simple to use, it is suitable when the training set is relatively small and may contain some noise and missing data.

In this recipe,we first load the required packages in step 1, read the data in step 2 , and identify the rows in the training partition (we set the random seed to enable you to match your results with ours) in step 3.

Step 4 builds the model using the naiveBayes() function and passing the formula and training partition as the arguments. Step 5 displays the conditional probabilities that the naiveBayes() function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required