EXPT-7
DEMONSTRATE NAVE BAYES CLASSIFICATION ALGORITHM
THEORY:
• Naive Bayes is a statistical classification technique based on Bayes
Theorem. It is one of the simplest supervised learning algorithms. Naive
Bayes classifier is fast, accurate and reliable algorithm. Naive Bayes
classifiers have high accuracy and speed on large datasets.
It is not a single algorithm but a family of algorithms where all of them
share a common principle, i.e. every pair of features being classified is
independent of each other.
CODE:
#import libraries
# load the iris dataset
from [Link] import load_iris
iris = load_iris()
# store the feature matrix (X) and response vector (y)
X = [Link]
y = [Link]
# splitting X and y into training and testing sets
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.4, random_state=1)
# training the model on training set
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
[Link](X_train, y_train)
# making predictions on the testing set
y_pred = [Link](X_test)
# comparing actual response values (y_test) with predicted
response values (y_pred)
from sklearn import metrics
print("Gaussian Naive Bayes model accuracy(in %):",
metrics.accuracy_score(y_test, y_pred)*100)
# Making the Confusion Matrix
from [Link] import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
cm
CONCLUSIONS: