Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In python please Q3.1: Consider the messages: A bird in the hand is worth two in the bush, The early bird gets the worm, Time
In python please
Q3.1: Consider the messages: "A bird in the hand is worth two in the bush", "The early bird gets the worm", "Time is money" "Honesty is the best policy" (a) Repeat the countvectorizer example in UnsupervisedML/Examples/Section03/SklearnText.ipynb for this new dataset including creation of the word cloud. (b) Repeat (a) using stop words ("the", "is" "in"). Stop words are typically common words that should not have an impact to sentiment or topic. Hint: create an instance of the countVectorizer with the format: CountVectorizer(stop_words=["the", "is", "in"]). Notice that the stop words are not in the word cloud. Q3.2: let's go back to the example from the demo with documents: "Call me soon", "CALL to win", "Pick me up soon" The goal of this exercise is to generate the Tfidf matrix from the Countvectorizer matrix. (a) The document frequency df(i) is the number of documents in which word i appears. For example, "call" appears in 2 documents (once we convert to lowercase) and "soon" appears in 2 documents. Starting with the Countvectorizer matrix, create a column vector (\# of word rows and 1 column) representing the document frequency. (b) Create the inverse document frequency vector idf(i) defined by following formula, where n is number of documents (column vector \# of word rows and 1 column) idf(i)=log(1+df(i)1+n)+1 (c) Compute the unscaled tfidf matrix defined by: Uij=Count(i,j)idf(i) Here Uij is entry of unscaled tfidf matrix for word i and document j and Count (i,j) is the result of the countvectorizer for word i and document j. (d) Compute the scaled tfidf matrix T, where entries are obtained by scaling the unscaled matrix U using the following formula (W is number of words) and compare with tfidf matrix obtained directly from sklearn Tfidf vectorizer (scale entries of column j of U by the length of column j to get T) Tij=[i=0W1Uij2]1/2UijStep 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