Question: Please solve it in Python. Need answers ASAP. Please show test results and output. Thank you! 3 (Bonus). Calculate Word Cooccurrences A word cooccurrence is

Please solve it in Python. Need answers ASAP. Please show test results and output. Thank you!
3 (Bonus). Calculate Word Cooccurrences A word cooccurrence is defined as two words, say w1, W2, both appear in a document (but they are not necessarily next to each other). If two words frequently appear together in a list of documents, for example, "sport" and "game", these words can become topic words. Define a function, find_coocur , as follows: take an array input similar to that of Q1, e.g. X of shape (m, n) calculate coocurrences between any pair of words, w1, W2 in the m documents, where wi # w2. Save the cooccrrences as an array of shape (n,n) return the cooccurrence array Again, do not use any loop. Just use array functions and broadcasting for high performance computation. In [6]: def find_coocur(x): C = None # add your code return c In [7]: x = np.array([[1,0,2,0], [1,1,0,1], [2,0,1,1]]) print(x) # For this toy example, wo and w3 coocur 1 time in d_1, # and 2 times d_2. Therefore, the total coocurrences is 3. find_coocur(x) [[1 0 2 0] [1 1 0 1] [2 0 1 1]] Out[7]: array([[0, 1, 4, 3], (1, 0, 0, 1) [4, 0, 0, 1), [3, 1, 1, 0]]) In [8]: # Structure of your solution to Assignment 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
