Elbow method
The silhouette score and elbow methods provide validation to the results you see from each. In a machine learning interview setting, you may get asked about one or the other but discussing the specifics of one in the context of the other would contribute greatly to your answer.
In this exercise, for each k
value, you will initialize a K-means model and use the inertia_
attribute to identify the sum of squared distances of samples to the nearest cluster center that, when plotted, appears to be an 'elbow' in the plot.
Recall in the last lesson that as the value of k
increased, the value for inertia_
decreased.
Already imported for you are matplotlib.pyplot
as plt
and KMeans
from sklearn.cluster
. The feature matrix X
has also been created for you.
This exercise is part of the course
Practicing Machine Learning Interview Questions in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create empty list
sum_of_squared_distances = ____