Write a function named cluster_membership (Z, C) that takes as input two numpy arrays, a data...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function named cluster_membership (Z, C) that takes as input two numpy arrays, a data array Z, and an array holding the centroid coordinates C, and returns as output a two dimensional numpy array of type interger, member_iter, and size n x 1 with each row indicating the cluster number k = 1,2,..., K) the data sample z,, i = 0, 1,..., n-1, belongs to. Your function should: 1. Find the number K of centroids from the size of C. 2. Find the dimensions, n X p, of the data array Z. 3. Create a one dimensional array D of size K to hold the L2 distances of each data sample z,, i = 0, 1, ..., n- 1, from each centroid. 4. Create the two dimensional array member_iter decribed above. 5. For each data sample z, i = 0, 1, ... , n - 1: A. Find the distance of the sample point to each of the centroids and store them into D. B. Use the numpy function argmin () to select the index corresponding to the minimum of those K distances and store that index into member_iter [i,0]. 6. Return the integer array member_iter. In order to verify your code, you can run the normalized, projected data stored in Z, with the centroids calculated in Problem 2A and check that the entries of the array member_iter are between 1 and 3. ]: # Enter your code here def cluster membership (Z, C): K = C.shape [0] n, p= Z.shape D = np.zeros(K, 'double') member_iter # for i in range(0,n): # for each data point Z[i,:], find for k in range (0,K): D[k] = # distance from point to centroid k (5A) above member_iter [i,0] = # index of D with smaller value +1 (5B) above return member_iter Write a function named cluster_membership (Z, C) that takes as input two numpy arrays, a data array Z, and an array holding the centroid coordinates C, and returns as output a two dimensional numpy array of type interger, member_iter, and size n x 1 with each row indicating the cluster number k = 1,2,..., K) the data sample z,, i = 0, 1,..., n-1, belongs to. Your function should: 1. Find the number K of centroids from the size of C. 2. Find the dimensions, n X p, of the data array Z. 3. Create a one dimensional array D of size K to hold the L2 distances of each data sample z,, i = 0, 1, ..., n- 1, from each centroid. 4. Create the two dimensional array member_iter decribed above. 5. For each data sample z, i = 0, 1, ... , n - 1: A. Find the distance of the sample point to each of the centroids and store them into D. B. Use the numpy function argmin () to select the index corresponding to the minimum of those K distances and store that index into member_iter [i,0]. 6. Return the integer array member_iter. In order to verify your code, you can run the normalized, projected data stored in Z, with the centroids calculated in Problem 2A and check that the entries of the array member_iter are between 1 and 3. ]: # Enter your code here def cluster membership (Z, C): K = C.shape [0] n, p= Z.shape D = np.zeros(K, 'double') member_iter # for i in range(0,n): # for each data point Z[i,:], find for k in range (0,K): D[k] = # distance from point to centroid k (5A) above member_iter [i,0] = # index of D with smaller value +1 (5B) above return member_iter
Expert Answer:
Answer rating: 100% (QA)
Heres the code for the clustermembership function following the steps youve ... View the full answer
Related Book For
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss
Posted Date:
Students also viewed these programming questions
-
Blooms Ltd. management recently reported adhering to a target capital structure. The company has the following target: a debt ratio of 50%. The book debt ratio is however 20% on total assets of R1...
-
For this prompt, consider your academic goals, including (but not limited to) such topics as how you plan to manage your time to fit in your studies; how you will build your skills, as needed; how...
-
2. From the solid model presented in the following figure, (a) find the coordinates of the center C stored in the model database and the respective mapping matrix [T] that maps point from WCS for the...
-
b) Salt enhances bioavailability. Taking a weak acid as an example, explain how salt in gastric fluid has better absorption compared to its acid form.
-
A simple beam AB is loaded as shown in the figure. Calculate the required section modulus S if Ïallow = 17,000 psi, L = 28 ft, P = 2200 lb, and q = 425 lb/ft. Then select a suitable I-beam (S...
-
Equipment is purchased at a cost of $80,000. As a result, annual cash revenues are expected to increase by $45,000; annual cash expenses are expected to increase by $12,000; straight-line...
-
Why is charisma so important to transformational leadership?
-
The comparative balance sheets for Rothlisberger Company as of December 31 are presented below. Additional information: 1. Operating expenses include depreciation expense of $42,000 and charges from...
-
A sports equipment company issued a $3 cumulative preferred stock issue. In 2010 the firms board of directors voted to omit dividends for both the companys common and preferred stock issues. Also,...
-
During 2020, your clients, Mr. and Mrs. Howell, owned the following investment assets: Investment Assets Date Acquired Purchase Price Brokers Commission Paid at Time of Purchase 300 shares of IBM...
-
Three paragraphs (6 to 8 sent. each) about recall (one - two reference links) Definition: "The most commonly employed metric used in an on-air test is recall - that is, the number of persons able to...
-
Brian is getting nervous about his stock holding in KalraCo. He bought the stock three years ago at $20 per share and the price is now $65 per share. KalraCo. has a policy of paying out 60 percent of...
-
The network uses a distance vector algorithm with hop count as the metric. The implementation has split horizon with poison reverse but it does not use triggered updates or hold down timers. Routers...
-
Shown below is a PMOS current mirror with VDD = 1.8 V, Ibias = 150 A, R = 2 k2, and all transistors sized (W/L) = 18 m/0.2 m and having the device parameters for the 0.18-m CMOS process. Ignore body...
-
Describe a time when the candidate faced a significant challenge on the job and how she/he worked to overcome the challenge.
-
The E.N.D. partnership has the following capital balances as of the end of the current year: Pineda Adams Fergie Gomez $ 300,000 270,000 260,000 250,000 $ 1,080,000 Total capital Answer each of the...
-
P12-1 Analyzing Comparative Financial Statements by Using Percentages LO12-5 The comparative financial statements prepared at December 31, Year 2, for Goldfish Company showed the following summarized...
-
According during to the IRS, individuals filing federal income tax returns prior to March 31 received an average refund of $1,088 in 2018. Consider the population of "last-minute" filers who mail...
-
Programs A and B are analyzed and found to have worst-case running times no greater than 150N log2 N and N2, respectively. Answer the following questions, if possible: a. Which program has the better...
-
Show that if the symbols are sorted by frequency, Huffman's algorithm can be implemented in linear time.
-
A multigraph is a graph in which multiple edges are allowed between pairs of vertices. Which of the algorithms in this chapter work without modification for multigraphs? What modifications need to be...
-
Determine whether the sequence of edges represents an Euler circuit in Multigraph 15: \(K ightarrow L ightarrow N ightarrow M ightarrow O ightarrow S ightarrow T ightarrow Q ightarrow U ightarrow P...
-
The trial balance for Kilda Services, Inc., at the end of July appears at the top of the opposite page. It does not balance because of a number of errors. Kildas accountant compared the amounts in...
-
Give an example of a pair of edges that could be duplicated to eulerize Multigraph 14. Use the graphs and multigraphs in Figure 12.354.
Study smarter with the SolutionInn App