How to ask question to the write of the specific article / K Means clustering

Hi All,

How can we ask the questions to specific old articles.

I am referring to the article :

Here the author Pulkit mentions *

" These values might vary every time we run this. Here, we are stopping the training when the centroids are not changing after two iterations. We have initially defined the diff as 1 and inside the while loop, we are calculating this diff as the difference between the centroids in the previous iteration and the current iteration."
after the loan prediction algorithm. I have two questions

  1. how are we stopping the training at 2 value, since we have run the code till the value 0. Also we are stopping at 2, because after that we have negative value. Right?
  2. We are minimising distance to 0, to find the best centroid for each cluster, but what is the significance of finding the number of iterations?


In example it doesn’t stop after second value but after 10 iterations when diff is 0.0 . (it doesn’t display diff after first iteration - so you see only 9 values)

And negative diff doesn’t matter.

It only uses 'j' to not stop after first value. (it also doesn’t display diff after first iteration)

if j == 0:

So it will run at least two iterations. And it can stop after two iterations but only if diff is 0.0 (when centroids are not changing). And you have it in text (I add only at least):

Here, we are stopping the training when the centroids are not changing after (at least) two iterations.

In example after two iterations diff is 338 so it doesn’t stop but it runs next iteration and it also doesn’t give 0.0 so it run another iteration, etc.

BTW: I would use variables which means something

first_loop = True

while diff != 0:
    # ... code ...

    if first_loop:
        #diff = 1 # doesn't need it because `diff` still is `1`
        first_loop = False
        diff = ...
        # ... code ... 


You can’t find how many iteration it will need - and this why it uses while-loop instead of for-loop

© Copyright 2013-2019 Analytics Vidhya