Lab Assignment - 6

Assignment-6 week 2 Aug

Learning Objective: Learn Naive Bayes Classifier

1.Problem Statement

A university wants to classify whether an email received by a student is Spam or Not Spam based on the presence or absence of certain words.

Consider the following training data, where:

  • 1 = word is present
  • 0 = word is absent
EmailFreeWinOfferSpam
E11111
E21101
E30111
E40101
E51010
E61000
E70010
E80000

Using the above training data, implement a Bernoulli Naive Bayes classifier to classify a new email having the following features:

FreeWinOffer
110

Tasks

  1. Calculate the prior probabilities of Spam and Not Spam.
  2. Calculate the conditional probabilities of each feature given the two classes.
  3. Use the Naive Bayes assumption to calculate the probability that the new email is Spam and Not Spam.
  4. Predict the class of the new email.
  5. Implement the same classification using BernoulliNB from Scikit-learn.
  6. Compare the manually calculated prediction with the Scikit-learn prediction.

2.Problem Statement

A college wants to predict whether a student is Eligible or Not Eligible for a scholarship based on categorical attributes.

The following data is collected from 12 students.

StudentAcademic PerformanceAttendanceFamily IncomeEligible
S1HighGoodLowYes
S2HighGoodHighYes
S3MediumGoodLowYes
S4HighAverageLowYes
S5MediumGoodHighYes
S6LowPoorLowNo
S7LowAverageHighNo
S8MediumPoorHighNo
S9LowPoorHighNo
S10MediumAverageLowYes
S11LowAverageLowNo
S12HighPoorHighNo

Using the above dataset, implement a Categorical Naive Bayes classifier to predict whether a new student is eligible for the scholarship.

The new student's details are:

Academic PerformanceAttendanceFamily Income
MediumGoodLow

Tasks

  1. Calculate the prior probabilities of Eligible = Yes and Eligible = No.
  2. Calculate the conditional probabilities of each categorical feature for the two classes.
  3. Use the Naive Bayes assumption to calculate the posterior probability for both classes.
  4. Predict whether the new student is Eligible or Not Eligible.
  5. Implement the same classification using CategoricalNB from Scikit-learn.
  6. Compare the manually calculated prediction with the Scikit-learn prediction.
  7. Repeat the prediction for the following students and observe the results:
StudentAcademic PerformanceAttendanceFamily Income
AHighGoodHigh
BLowPoorHigh
CMediumAverageLow

3.Problem Statement

A college wants to automatically classify student feedback into one of three categories:

  • Academic
  • Infrastructure
  • Placement

The following training data contains the word counts in each feedback message.

FeedbackExamCourseFacultyLabComputerPlacementJobInterviewCategory
F122100000Academic
F212200000Academic
F321100000Academic
F400032000Infrastructure
F500023000Infrastructure
F600012000Infrastructure
F700000321Placement
F800000231Placement
F900000122Placement

Tasks

  1. Calculate the prior probability of each category.
  2. Calculate the word probabilities for each category using Laplace smoothing.
  3. Using the Multinomial Naive Bayes formula, classify the following new feedback represented by its word counts:
ExamCourseFacultyLabComputerPlacementJobInterview
11100000
  1. Calculate the posterior probability for each of the three categories.
  2. Predict the category having the highest posterior probability.
  3. Implement the same classification using MultinomialNB from Scikit-learn.
  4. Compare the manually calculated result with the Scikit-learn result.

4.Problem Statement

Implement a Naïve Bayes classifier to categorize text documents into topics using the 20 Newsgroups dataset. Compare the performance of Multinomial Naïve Bayes with Bernoulli Naïve Bayes.
Tasks:
● Load and preprocess the 20 Newsgroups dataset.
● Implement Multinomial Naïve Bayes and Bernoulli Naïve Bayes classifiers.
● Evaluate and compare the performance of both models using metrics such as
accuracy and F1-score.
● Discuss the strengths and weaknesses of each Naïve Bayes variant for text
classification.

Comments

Popular posts from this blog

Machine Learning Lab PCCSL508 Semester 5 KTU CS 2024 Scheme manual - Dr Binu V P

Explore California Housing Dataset

Lab Assignment-1