0% found this document useful (0 votes)
5 views2 pages

Naive Bayes Classification with Iris Dataset

The document explains the Naive Bayes classification algorithm, highlighting its basis on Bayes Theorem and its effectiveness in handling large datasets with high accuracy and speed. It includes a Python code example that demonstrates how to implement the Gaussian Naive Bayes classifier using the iris dataset, including data splitting, model training, and accuracy evaluation. The document concludes with a mention of the confusion matrix for assessing model performance.

Uploaded by

anitha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Naive Bayes Classification with Iris Dataset

The document explains the Naive Bayes classification algorithm, highlighting its basis on Bayes Theorem and its effectiveness in handling large datasets with high accuracy and speed. It includes a Python code example that demonstrates how to implement the Gaussian Naive Bayes classifier using the iris dataset, including data splitting, model training, and accuracy evaluation. The document concludes with a mention of the confusion matrix for assessing model performance.

Uploaded by

anitha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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:

You might also like