# Understanding K-mean clusters

I have been having some misconceptions about the size of K clusters. To start with, I created a set of random inputs: x1 and x2

I made a scatterplot of these inputs, as shown below

From the figure above, it is safe to assume the number of clusters K = 3.

I then initialize my clusters using the following function:

The plot shows the following result:

And after several randomizations, just like Professor Andrew advised, I got this impressive plot:

The professor said the number of columns of Mu_k would have to be the same as the number of features in our training sample. In my implementation here, I created two features and the length of my Mu_k = 2. Is that the proper implementation of the professor’s advice?

Can I go on to implement the complete algorithm?

That’s incorrect implementation to get the best centroids points that make the minimum between assigned points and the cluster that it assigned to, also you had been chosen the initial centroids correctly but you didn’t make a list of the centroids points to can update it’s points using k-means algorithm or any other cluster algorithm
The 5 Steps to create K-means Clustering model :

Step 1. Randomly pick k data points as our initial Centroids. like what you did
Step 2. Find the distance (Euclidean distance for our purpose) between each data points in our training set with the k centroids.
Step 3. Now assign each data point to the closest centroid according to the distance found.
Step 4. Update centroid location by taking the average of the points in each cluster group.
Step 5. Repeat the Steps 2 to 4 till our centroids don’t change.
in the course 3 of the specialization there are an assignment about how to create K-means Clustering model from scratch and also I think this ink can help you Create a K-Means Clustering Algorithm from Scratch in Python | by Turner Luke | Towards Data Science

Thanks!
Abdelrahman

Yes. I understand. That was why I said

Since I was only trying to see what’s going on, I had to manually iterate over different random picks.

I understand that in actual implementation, I will have to follow the algorithm as you listed.