Why are lowest distance and closest cluster set to -1

Screen Link:https://app.dataquest.io/m/40/k-means-clustering/11/step-1-continued

I had a question on the two variables in the assign_to_cluster function
lowest_distance and closest_cluster both which are set to -1.

Where are these values coming from?

4 Likes

lowest_distance is set to -1 since you need a value that will deem the first if statement True in the first iteration. The reason it’s True is because lowest_distance is not reassigned again before the if statements (while in the first iteration) and euclidean_distance is always positive. Thus, you could set it to any negative number.
closest_cluster is initiated to -1, but that is optional anyway.

1 Like