Question: Your task: Define build _ cluster _ matrix as follows: Given a k - means clustering result, construct a k - means assignment assignment matrix.
Your task: Define buildclustermatrix as follows:
Given a kmeans clustering result, construct a kmeans assignment assignment matrix. From the preceeding discussion, it is R matrix.
Inputs:
labels: A D array where labelsi is the cluster ID assigned to document i
maxlabel: The largest cluster ID plus That is labelsi maxlabel for all i
Return: R a scipy COO matrix
Steps:
The returned matrix R should have lenlabels rows and maxlabel columns. It should only have entries equal to at positions ij where j labelsi; all other entries should be regarded as zero values and therefore not stored explicitly.
Example:
Suppose we run:
buildclustermatrixnparray
A correct implementation would return:
Solution:
def buildclustermatrixlabels: npndarray, maxlabel: int spsparse.coomatrix:
##code here
demoR buildclustermatrixnparray
printdemoR
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
