Answered step by step
Verified Expert Solution
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
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 ( 0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started