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)
The function clustermembership takes two input parameters an array Z representing the data samples a... 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
-
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 3.70-F capacitor is charged by a 12.0-V battery. It is disconnected from the battery and then connected to an uncharged 5.00-F capacitor (Fig.17-43). Determine the total stored energy (a) Before...
-
Researchers collected a simple random sample of the times that 81college students required to earn their bachelors degrees. The sample has a mean of 4.8 years and a standard deviation of 2.2 years...
-
CGI Federal, Inc., is a corporation that provides a number of services to the United States Passport Agency, included the processing of passport application. Passport applicants must submit sensitive...
-
Dan Watson started a small merchandising business in 2016. The business experienced the following events during its first year of operation. Assume that Watson uses the perpetual inventory system. 1....
-
Scenario 11:Accountant 11 is a senior accountant. She says: I recommended a wonderful coffee serviceto my audit client, I received a commission from the coffee service company, can I take...
-
Following the flowchart write in python IDLE Yes Start today Bottles -0 counter - 1 totalBottles - 8 totalPayout-0 Loop -0 counter > 7 NO "Enter the number of bottles returned for today GET...
-
"There is a fusion of equity and common law". Is this true? Explain. "There is a fusion of equity and common law". Is this true? Explain.
-
1. Please write a few sentences refuting the following statement proving it is false Cash advance/payday lending is financial services for lower-income people that help them get ahead using the facts...
-
best financial practice: explain why budgeting important for an hospital given the current policy and regulatory environment.
-
People live in a data-driven world. In personal lives, people are surrounded by websites offering weather or airfare predictions, and in professional lives, people deal with revenue projections and...
-
In many cities, African-American people fare worse than White or Hispanic people fare on a variety of indicators. For this assignment, you are tasked with creating a report (in the format of your...
-
A filtrate volume of 5 cm is collected in 10 min in a filter press having an area of 90 cm?. A spurt loss of 0.5 cm' was observed. Compute the API water loss.
-
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...
-
The following table shows the interest rates on the fixed and floating borrowing choices available to three firms. Firms A and B want to be exposed to a floating interest rate while Firm C would...
-
Futures contracts are standardized contracts for the delivery of a specified quantity of a commodity or financial instrument on a prearranged future date, at an agreed- upon price. They are a bet on...
-
Derivatives transfer risk from one person or firm to another. They can be used in any combination to unbundle risks and resell them.
Study smarter with the SolutionInn App