October 2018
Intermediate to advanced
172 pages
4h 6m
English
While explaining how the k-means algorithm works, we mentioned how the algorithm terminates once it finds the optimal number of clusters. When picking clusters arbitrarily using scikit-learn, this is not always the case. We need to find the optimal number of clusters, in this case.
One way that we can do this is by a measure known as inertia. Inertia measures how close the data points in a cluster are to its centroid. Obviously, a lower inertia signifies that the groups or clusters are tightly packed, which is good.
In order to compute the inertia for the model, we use the following code:
# Inertia of present modelk_means.inertia_
The preceding code produced an inertia value of 4.99 × 10 ^ 17, which is extremely ...
Read now
Unlock full access