Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with code needed where it says replace with proper code To color each point according to its cluster, we need to specify a label

image text in transcribed

Help with code needed where it says replace with proper code

To color each point according to its cluster, we need to specify a label for each point. A label is just an integer >= 0. The label for all points in the same cluster must be the same. So we make a function get_labels(x, centroids). This function takes in our N x 2 data matrix X, and our k x 2 centroid matrix. It should return a Nx1 numpy array labels, such that labels[i] is the index of the cluster of the i 'th point. To do this, we should iterate over all the points. For each point we should iterate over all the centroids, and choose the one which is the closest (least Euclidean distance) to the point. We can simply use the index of that centroid ( 0 = 0. The label for all points in the same cluster must be the same. So we make a function get_labels(x, centroids). This function takes in our N x 2 data matrix X, and our k x 2 centroid matrix. It should return a Nx1 numpy array labels, such that labels[i] is the index of the cluster of the i 'th point. To do this, we should iterate over all the points. For each point we should iterate over all the centroids, and choose the one which is the closest (least Euclidean distance) to the point. We can simply use the index of that centroid ( 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

4. Did you rethink your decision?

Answered: 1 week ago

Question

3. Did you seek anyones advice?

Answered: 1 week ago

Question

7. What traps should she avoid?

Answered: 1 week ago