Naive Bayes Classifier using R.

TrilokiGupta 1,623 views 25 slides Mar 30, 2018
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

Classification of Iris data set with Naive Bayes in R.


Slide Content

NAÏVE BAYES CLASSIFIER USING R RAKSHIT G DWARAM 205217027 TRILOKI GUPTA 205217006

Naïve B ayes It is a classification technique based on Bayes’ Theorem  Naive Bayes classifier assumes that the presence of a particular feature in a class is unrelated to the presence of any other feature.

Why naive Even if these features depend on each other or upon the existence of the other features, all of these properties independently contribute to the probability of an object and that is why it is known as ‘Naive’.

Why use naïve bayes Naive Bayes model is easy to build U seful for very large data sets . O utperform even highly sophisticated classification methods.

Naïve bayes formula Bayes theorem provides a way of calculating posterior probability P( c|x ) from P(c), P(x) and P( x|c ).

Formula

Advantages of naïve bayes It is easy and fast to predict class of test data set . It also perform well in multi class prediction Naive Bayes classifier performs better compare to other models like logistic regression Require less training data. It perform well in case of categorical input variables compared to numerical variable(s.

Disadvantages Zero Frequency bad estimator. Another limitation of Naive Bayes is the assumption of independent predictors.

Applications of Naive Bayes Algorithms Real time Prediction Text classification Spam Filtering Sentiment Analysis

Continued… Multi class Prediction Recommendation System

How to build a basic model using Naive Bayes in R Using library ‘e1071’ Using library ‘caret’

R Code library(e1071) #Default Paramters nb_default <-  naiveBayes (response~., data=train[,-4]) default_pred <- predict( nb_default , test, type="class")   table( default_pred , test$response,dnn =c(" Prediction","Actual ")) #          Actual #Prediction   0   1 #         0 138  16 #         1  12  14

Naïve bayes in r naiveBayes (formula, data, laplace = 0, subset, na.action = na.pass ) The formula is traditional Y~X1+X2+…+ Xn The data is typically a dataframe of numeric or factor variables. laplace  provides a smoothing effect subset lets you use only a selection subset of your data based on some boolean filter na.action  lets you determine what to do when you hit a missing value in your dataset.

Iris data set

Confusion matrix

Plot on graph naive_iris <- NaiveBayes ( iris$Species ~ ., data = iris) plot( naive_iris )

Precision, Recall and Accuracy

Thank you