Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Import Statements Run the cell below to import the NumPy, Matplotlib, and math packages. [ ] import numpy as np import matplotilib.pyplot as plt import
Import Statements Run the cell below to import the NumPy, Matplotlib, and math packages. [ ] import numpy as np import matplotilib.pyplot as plt import math Four arrays have been created to store the datasets that you will be working with in this lab. Running the cell below will import those arrays into your workspace. We will describe the imported arrays later in this notebook. The cell will also import some functions that will be used to test your code in Problem 7. Run that cell now. fron MATH_599.1ab_08 import x1,y1,x2,y2 fron MATH_599.1ab_68 import unit_test_1, unit_test_2, unit_test_3 Problem 5 - Naive Bayes Classifier In this problem, you will build a binary naive Bayes classifier. You will then apply the classifier to perform spam detection. The training data for this problem is stored in the arrays X1 and y1 that were imported near the beginning of this notebook. The array X1 is a 2D feature array with 10 features and 10,000 observations. Each observation is intended to represent a single email. Each feature is associated with a specific word that might be associated with a spam email. The features are binary (0/1) variables indicating the presence (1) or absence (0) of the word in the email. The array y1 contains the training labels. The target variable Y is a binary variable indicating whether the email is spam (1) or not spam ( 0 ). The shapes of these arrays are printed below. [ ] print(X1.shape) print(y1.shape) Part 5.A Complete the definition of the function naive_bayes() in the cell below. The role of the three parameters are as follows: - x is a 2D array containing the training features. - y is a 1D array containing the training labels. - x is a 1D array containing features for an observation to be classified. The function should calculate a score for both classes (class 0 and class 1), and then calculate and return the likelihood ratio. These calculations are explained in the "Naive Bayes Classifier" lesson. [ ] def naive_bayes (x,y,x) : A Add code here Part 5.B The cell below provides feature vectors for three emails. Apply the naive Bayes classifier to each of these emails and print the resulting likelihood ratios. Recall that any email with a likelihood ratio greater than 1 should be classified as spam. [ ] enai1_1 =[,1,,,1,,,,1,] enai1_2 =[1,,1,,,,,,,1] enai1_3 =[,1,,,,1,,,1,] "I Add code here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started