Aan de slagGa gratis aan de slag

Elbow method on uniform data

In the earlier exercise, you constructed an elbow plot on data with well-defined clusters. Let us now see how the elbow plot looks on a dataset with uniformly distributed points. You may want to display the data points before proceeding with the exercise.

The data is stored in a pandas DataFrame, uniform_data. x_scaled and y_scaled are the column names of the standardized X and Y coordinates of points.

Deze oefening maakt deel uit van de cursus

Cluster Analysis in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

distortions = []
num_clusters = range(2, 7)

# Create a list of distortions from the kmeans function
for i in ____:
    cluster_centers, distortion = ____
    ____.append(____)

# Create a DataFrame with two lists - number of clusters and distortions
elbow_plot = pd.DataFrame({'num_clusters': ____, 'distortions': ____})

# Creat a line plot of num_clusters and distortions
sns.____(x=____, y=____, data=____)
plt.xticks(num_clusters)
plt.show()
Code bewerken en uitvoeren