Question: 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

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
Get step-by-step solutions from verified subject matter experts
