Question: Python Coding To start, implement the update_model function in the Naive Bayes Block. Make sure to read the function comments so you know what to

Python Coding

To start, implement the update_model function in the Naive Bayes Block. Make sure to read the function comments so you know what to update. Also review the NaiveBayes class variables in the def __init__ method of the NaiveBayes class to get a sense of which statistics are important to keep track of. Once you have implemented update_model, run the train model function using the code below. What is the size of the vocabulary used in the training documents? Youll need to provide the path to the dataset you downloaded to run the code.

def update_model(self, bow, label):

"""

IMPLEMENT ME!

Update internal statistics given a document represented as a bag-of-words

bow - a map from words to their counts

label - the class of the document whose bag-of-words representation was input

This function doesn't return anything but should update a number of internal

statistics. Specifically, it updates:

- the internal map the counts, per class, how many times each word was

seen (self.class_word_counts)

- the number of words seen for each label (self.class_total_word_counts)

- the vocabulary seen so far (self.vocab)

- the number of documents seen of each label (self.class_total_doc_counts)

"""

pass

nb = NaiveBayes(PATH_TO_DATA, tokenizer=tokenize_doc)

nb.train_model()

if len(nb.vocab) == 251637:

print ("Great! The vocabulary size is {}".format(251637))

else:

print ("Oh no! Something seems off. Double check your code before continuing. Maybe a mistake in update_model?")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!