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
- Naive bayes performs better than other
models when the assumption of independent variables hold true.
- Naive bayes requires less amount of data for
training, therefore need less training time.
- Simple, fast and easy to implement.
- It can be used for both binary and multi class
predictions
Disadvantages
- It is hard to find such data sets where all
independent variables are independent from one another
Use Cases
- Text Classification
- Spam Filtering
- Sentiment Analysis
- 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