Question: We use this function to pre - calculate a W for X . The code cell below loads this W: with open ( ' resource
We use this function to precalculate a W for X The code cell below loads this W:
with openresourceasnlibpublicdataWdill', rb as fp:
W dill.loadfp
print Wshape
Output:
Your task: Define getnmfclusters as follows:
Determine cluster assignments from an NMF computation.
Return:
labels: Cluster assignments: for each row i of W labelsi is the cluster column assignment.
ids: Cluster IDs: a Numpy array containing the values from to m
sizes: Cluster sizes: sizesc is the number of rows of W that are assigned to cluster c
STEPS:
let m be the number of clusters, which is equal to the number of columnsof W
For each row i of W assign it to the cluster c having largest value of Wi c
the ids array is simply a Numpy array of length m whose values go from to m
For each cluster c count how many rows were assigned to it and store that as sizesc
Example: For the demo code, a correct implementation should return:
array array array
Solution:
def getnmfclustersW: npndarraynpndarray, npndarray, npndarray:
##code here##
with openresourceasnlibpublicdatademogetnmfclustersWdill', rb as fp:
demoW dill.loadfp
printdemo input W:
pprintdemoW
print
Your output:"
printgetnmfclustersdemoW
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
