Find the new location of the centroid by taking the mean of all the observations in each cluster

Coding Exercise 2: KMeans Clustering
(Adopted from Dr. RogelSalazar)

In Monday’s class, we learned about Kmeans clustering. You are asked to work on the following coding exercise in Python to model Kmeans clustering. To ensure successful completion of the exercise, please read the instructions carefully and follow the code stepbystep. After completing the exercise, please save your code, visual graphs, and results in the same format as the first exercise. Finally, submit the document in PDF format.

Before we start, here is an easytofollow recipe for all kmeans models:

1. Decide how many clusters you want, i.e. choose your “k

2. Randomly assign a centroid to each of the k clusters

3. Calculate the distance of all observation to each of the k centroids

4. Assign observations to the closest centroid

5. Find the new location of the centroid by taking the mean of all the observations in each cluster

6. Repeat steps 35 until the centroids do not change position