Aan de slagGa gratis aan de slag

Elbow method on distinct clusters

Let us use the comic con dataset to see how the elbow plot looks on a dataset with distinct, well-defined clusters. You may want to display the data points before proceeding with the exercise.

The data is stored in a pandas DataFrame, comic_con. x_scaled and y_scaled are the column names of the standardized X and Y coordinates of people at a given point in time.

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(1, 7)

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

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

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