Saturday, 4 July 2020

How Naive Bayes Works ?

Naive bayes is a supervised machine learning algorithm that works for both classification and regression problems. This algorithms works on bayes theorem to calculate the class of data sets.

Bayes theorem works on assumption that all variables are independent of one another. This algorithm best works for large data set

Advantages
  1.  Naive bayes performs better than other models when the assumption of independent variables hold true.
  2. Naive bayes requires less amount of data for training, therefore need less training time.
  3. Simple, fast and easy to implement.
  4. It can be used for both binary and multi class predictions
Disadvantages
  1. It is hard to find such data sets where all independent variables are independent from one another
Use Cases
  1. Text Classification
  2. Spam Filtering
  3. Sentiment Analysis
  4. Naive bayes classifier with collaborative filtering is used to make recommendation engine.

Python Code

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split from sklearn.naive_bayes import GaussianNB X, y = load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.7, random_state=32) model_nb = GaussianNB() y_pred = model_nb.fit(X_train, y_train).predict(X_test)




No comments:

Post a Comment