Prac4 AAM
Prac4 AAM
Aim: - write a python programming code applying naive Bayesian for classification using
suitable dataset.
Introduction:
Naive Bayes is a simple yet effective probabilistic classifier based on Bayes' theorem with the assumption of
independence between features.
In this Python programming code, we'll implement Naive Bayes for classification using a suitable dataset. We'll
explore how Naive Bayes can be applied to classify instances into different classes based on the features
available in the dataset.
Code:
# Importing necessary libraries
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score, classification_report
from sklearn.datasets import load_iris
print("Accuracy:", accuracy)
print("Classification Report:")
print(report)
Output:
Explanation:
In this code, we first import necessary libraries including train_test_split for splitting the dataset, GaussianNB
for Naive Bayes classification, accuracy_score and classification_report for evaluating the model. We then
load a suitable dataset (iris dataset in this case) using load_iris() function from sklearn.datasets.
We split the dataset into training and testing sets using train_test_split() function. Next, we initialize a
Gaussian Naive Bayes classifier and fit it to the training data using fit() method. Then, we make predictions on
the testing data using predict() method.
Finally, we evaluate the performance of the model by calculating accuracy using accuracy_score() and
generating a classification report using classification_report().
Outcomes:
The outcomes of this code include the accuracy of the Naive Bayes classifier and a classification report
providing details such as precision, recall, and F1-score for each class.
Conclusion:
Naive Bayes is a simple yet powerful classification algorithm that can be effectively applied to various datasets.
In this code, we demonstrated how to implement Naive Bayes for classification using a suitable dataset and
evaluated its performance. With its simplicity and efficiency, Naive Bayes can be a valuable tool for
classification tasks in machine learning.