0% found this document useful (0 votes)
19 views7 pages

Ai 5

The document describes two tasks to implement the Naive Bayes classification algorithm. Task 1 involves using a Python implementation of Naive Bayes to classify samples in a loan default dataset. Task 2 requires building a Naive Bayes classifier from scratch to predict diabetes status using various medical features. Both tasks calculate probabilities to classify new samples and output the predicted classes.

Uploaded by

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

Ai 5

The document describes two tasks to implement the Naive Bayes classification algorithm. Task 1 involves using a Python implementation of Naive Bayes to classify samples in a loan default dataset. Task 2 requires building a Naive Bayes classifier from scratch to predict diabetes status using various medical features. Both tasks calculate probabilities to classify new samples and output the predicted classes.

Uploaded by

meesam2021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 7

GROUP MEMBERS:

ALEENA SEHAR BSCS-2021-35


MEESAM IMRAN BSCS-2021-01
MUNIM NAEEM BSCS-2021-04

ARTIFICIAL INTELLIGENCE
LAB NO 5
NAIVE BAYES ALGORITHM
TASK NO 1:

Objective:
Implement the Naïve Bayes classification model in Python to classify a given test sample based on
a provided training dataset. The model will utilize Gaussian probability distribution for numerical
features to predict the class of the test sample.

Task Steps:

1. Understanding Naïve Bayes:


• Explain the concept of Naïve Bayes as a probabilistic classifier.
• Describe the assumption of feature independence within the feature vector.

2. Algorithm Explanation:
• Provide a detailed breakdown of the Naïve Bayes algorithm steps:
• Computation of prior probabilities for each class based on the training data labels.
• Calculation of likelihood probabilities for the test sample against training samples using
Gaussian probability density function.
• Computation of posterior probabilities by combining prior probabilities and likelihoods.
• Prediction of the test sample's class based on maximum posterior probability.

3. Python Implementation:
• Share the Python code implementing the Naïve Bayes classifier.
• Highlight the key functions and their purposes:
• `compute_prior_probability`: Computes prior probabilities for each class.
• `gaussian_likelihood`: Computes likelihood probabilities using Gaussian distribution.
• `naive_bayes`: Implements the Naïve Bayes algorithm for classification.
• Explain the structure of the code, including the representation of training data, labels, and
the test sample.

4. Dataset Description:
• Describe the provided dataset consisting of age, loan amount, and class (defaulter).
• Explain the significance of the features (age, loan amount) and the target variable (class).

5. Classification Process:
• Discuss the steps involved in classifying the test sample using the Naïve Bayes model:
• Loading the provided training dataset.
• Initializing the test sample for classification.

6. Execution and Result:


• Instruct the execution of the Python code with the provided dataset and test sample.
• Display and interpret the output, indicating the predicted class for the given test sample.

7. Discussion:
• Discuss the implications of the Naïve Bayes classifier's outcome on predicting the class
of the test sample.
• Analyze the model's efficiency and its potential applications in similar classification
tasks.

8. Conclusion:
• Summarize the effectiveness of the Naïve Bayes model in classifying the test sample.
• Provide insights into possible areas for improvement or further exploration.

Code:
Output:

TASK NO 2:

Objective:
Implement the Naïve Bayes classification algorithm from scratch using Python for the diabetes
dataset, comprising features like Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin,
BMI, DiabetesPedigreeFunction, Age, and Outcome.
Steps Taken:

1. Data Loading and Preprocessing:


• Loaded the 'Diabeties.csv' dataset.
• Identified features (Pregnancies, Glucose, etc.) and the target class (Outcome).

2. 2-Fold CrossValidation:
Split the dataset into training and testing sets using a 2-fold cross-validation approach
(test_size=0.5, random_state=42).

3. Naïve Bayes Implementation:


• Defined a function for computing Gaussian probability using mean and standard
deviation.
• Calculated mean and standard deviation for each feature for both Outcome classes (0 and
1).

4. Prediction and Accuracy Calculation:


• Predicted the classes for the test set based on likelihood and prior probabilities.
• Computed accuracy by comparing the predicted classes with the actual classes using
accuracy_score function.

Code Implementation Summary:

• Imported necessary libraries: pandas, numpy.


• Loaded the 'Diabeties.csv' dataset and split it into features and target class.
• Performed 2fold crossvalidation to create training and testing sets.
• Implemented Gaussian probability calculation function for the Naïve Bayes algorithm.
• Calculated mean and standard deviation for each feature for both Outcome classes.
• Predicted the classes for the test set using likelihood and prior probabilities.
• Calculated accuracy using the predicted and actual classes.

Conclusion:

• Successfully implemented Naïve Bayes classifier from scratch for the diabetes dataset.
• Achieved accuracy in predicting the classes using Gaussian probabilities and prior
probabilities.
• Adjustments made regarding function representations and library imports resulted in the
successful execution of the algorithm.

Code:
Output:

You might also like