Naïve Bayes – R

0
129

Naive Bayes: In the continuation of Naive Bayes algorithm, let us look into the basic codes in R to implement Naive Bayes. We will start with installation of packages required for Naive Bayes then move onto the commands required for the implementation of algorithm.

We will try to predict probability of default/Non-Default using Naïve Bayes algorithm. Please download the data provided in the data repository section.

Step 1. Set up a working library. Setting up a working directory makes life very easy. We can refer to any file saved in working library without mentioning location again and again.

NAB_1

Step 2: Import the data set into R-Studio using following commands.

NAB_2

Step 3. : Install the package required for Naïve Bayes. We would install “e1071” for linear regression.

NAB_3

Step 4: Our data set has 5 variables but for analysis we would use just last three variables. So we would select last tree variable using following commands.

NAB_4

Step 5: Change the Response variable to Factors

NAB_5

Step 6: Develop Naive Bayes algorithm using following commands

NAB_6

Step 7. Predicting the output

NAB_7

Step 8: Checking the accuracy with confusion matrix.

NAB_8

 

 

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here