O'Reilly logo

Learning Predictive Analytics with R by Eric Mayor

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

Working with Naïve Bayes in R

For this example of working with Naïve Bayes in R, we are going to use the Titanic dataset. The classification problem we have is to know whether or not individuals died in the Titanic accident. We will create a training dataset and a testing dataset (in order to test how well the classifier performs).

The first thing we need to know is how to convert the Titanic dataset (of class table) to a data frame:

1  Titanic.df_weighted = data.frame(Titanic)

Let's have a look at the dataset:

 

Class

Sex

Age

Survived

Freq

1

1st

Male

Child

No

0

2

2nd

Male

Child

No

0

3

3rd

Male

Child

No

35

4

Crew

Male

Child

No

0

5

1st

Female

Child

No

0

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