Question: i have python file i want to solve the exercise Exercise 1 Your task is to implement the function that generates a dictionary, recording the
i have python file i want to solve the exercise
Exercise
Your task is to implement the function that generates a dictionary, recording the frequency with which each word in the dataset appears as spam or ham
In :
import numpy as
def getwordfrequency :
"I"!
Calculate the frequency of each word in a set of emails categorized as spam or not spam
Parameters:
X numpyarray: Array of emails, where each email is represented as a list of words.
Y numpyarray: Array of labels corresponding to each email in X indicates spam, indicates ham.
Returns:
worddict dict: A dictionary where keys are unique words found in the emails, and values
are dictionaries containing the frequency of each word for spam and not spam emails.
# Creates an empty dichar lab
worddict
### START CODE HERE ###
### END CODE HERE ###
return worddict
# Example usage:
# Assuming we have numpy arrays and with the email data and corresponding labels:
# nparray # Replace with actual email text data split into words
# nparray # Replace with actual labels or
# wordfreqdict getwordfrequency
# printwordfreqdict
In : testoutput getwordfrequencylike'going','river'love 'deep', 'river'hate 'river'
printtestoutput
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
