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 |
Get R: Predictive Analysis 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.