# What's the difference between finding the average Euclidean distance and using inertia_ in KMeans in sklearn?

I've found two different approaches online when using the Elbow Method to determine the optimal number of clusters for K-Means.

One approach is to use the following code:

distortions_2.append(sum(np.min(cdist(data
, kmeanModel.cluster_centers_
, 'euclidean')
, axis = 1)) / data.shape[0])


Another is to use inertia_ from sklearn.cluster.KMeans:

distortions_3.append(kmeanModel.inertia_)


When I plot the results (using the same random states) both give different results but I'm not sure what the differences are, can anyone help?

• you can post this question here and get some help – seralouk May 22 '18 at 21:04
• @seralouk do not suggest people to post duplicates! If it is better suited for CV, it should be migrated and not duplicated! – Has QUIT--Anony-Mousse May 23 '18 at 5:03
• this will need to be merged with datascience.stackexchange.com/questions/31989/… – user16777 May 27 '18 at 12:23
• This has already been answered here. – JahKnows May 27 '18 at 12:59
• – JahKnows May 27 '18 at 12:59