1. Learn
  2. /
  3. Courses
  4. /
  5. Practicing Machine Learning Interview Questions in Python

Exercise

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.

Instructions 1/3

undefined XP
    1
    2
    3
  • Create an empty list named sum_of_squared_distances.