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
| Free | Win | Offer | Spam | |
|---|---|---|---|---|
| E1 | 1 | 1 | 1 | 1 |
| E2 | 1 | 1 | 0 | 1 |
| E3 | 0 | 1 | 1 | 1 |
| E4 | 0 | 1 | 0 | 1 |
| E5 | 1 | 0 | 1 | 0 |
| E6 | 1 | 0 | 0 | 0 |
| E7 | 0 | 0 | 1 | 0 |
| E8 | 0 | 0 | 0 | 0 |
Using the above training data, implement a Bernoulli Naive Bayes classifier to classify a new email having the following features:
| Free | Win | Offer |
|---|---|---|
| 1 | 1 | 0 |
Tasks
- Calculate the prior probabilities of Spam and Not Spam.
- Calculate the conditional probabilities of each feature given the two classes.
- Use the Naive Bayes assumption to calculate the probability that the new email is Spam and Not Spam.
- Predict the class of the new email.
-
Implement the same classification using
BernoulliNBfrom Scikit-learn. - 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.
| Student | Academic Performance | Attendance | Family Income | Eligible |
|---|---|---|---|---|
| S1 | High | Good | Low | Yes |
| S2 | High | Good | High | Yes |
| S3 | Medium | Good | Low | Yes |
| S4 | High | Average | Low | Yes |
| S5 | Medium | Good | High | Yes |
| S6 | Low | Poor | Low | No |
| S7 | Low | Average | High | No |
| S8 | Medium | Poor | High | No |
| S9 | Low | Poor | High | No |
| S10 | Medium | Average | Low | Yes |
| S11 | Low | Average | Low | No |
| S12 | High | Poor | High | No |
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 Performance | Attendance | Family Income |
|---|---|---|
| Medium | Good | Low |
Tasks
- Calculate the prior probabilities of Eligible = Yes and Eligible = No.
- Calculate the conditional probabilities of each categorical feature for the two classes.
- Use the Naive Bayes assumption to calculate the posterior probability for both classes.
- Predict whether the new student is Eligible or Not Eligible.
-
Implement the same classification using
CategoricalNBfrom Scikit-learn. - Compare the manually calculated prediction with the Scikit-learn prediction.
- Repeat the prediction for the following students and observe the results:
| Student | Academic Performance | Attendance | Family Income |
|---|---|---|---|
| A | High | Good | High |
| B | Low | Poor | High |
| C | Medium | Average | Low |
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.
| Feedback | Exam | Course | Faculty | Lab | Computer | Placement | Job | Interview | Category |
|---|---|---|---|---|---|---|---|---|---|
| F1 | 2 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | Academic |
| F2 | 1 | 2 | 2 | 0 | 0 | 0 | 0 | 0 | Academic |
| F3 | 2 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | Academic |
| F4 | 0 | 0 | 0 | 3 | 2 | 0 | 0 | 0 | Infrastructure |
| F5 | 0 | 0 | 0 | 2 | 3 | 0 | 0 | 0 | Infrastructure |
| F6 | 0 | 0 | 0 | 1 | 2 | 0 | 0 | 0 | Infrastructure |
| F7 | 0 | 0 | 0 | 0 | 0 | 3 | 2 | 1 | Placement |
| F8 | 0 | 0 | 0 | 0 | 0 | 2 | 3 | 1 | Placement |
| F9 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 2 | Placement |
Tasks
- Calculate the prior probability of each category.
- Calculate the word probabilities for each category using Laplace smoothing.
- Using the Multinomial Naive Bayes formula, classify the following new feedback represented by its word counts:
| Exam | Course | Faculty | Lab | Computer | Placement | Job | Interview |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
- Calculate the posterior probability for each of the three categories.
- Predict the category having the highest posterior probability.
-
Implement the same classification using
MultinomialNBfrom Scikit-learn. - Compare the manually calculated result with the Scikit-learn result.
Comments
Post a Comment