BaşlayınÜcretsiz Başlayın

Visualize clusters with matplotlib

We have discussed that visualizations are necessary to assess the clusters that are formed and spot trends in your data. Let us now focus on visualizing the footfall dataset from Comic-Con using the matplotlib module.

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. cluster_labels has the cluster labels. A linkage object is stored in the variable distance_matrix.

Bu egzersiz

Cluster Analysis in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Import the pyplot class from matplotlib module as plt.
  • Define a colors dictionary for two cluster labels, 1 and 2.
  • Plot a scatter plot with colors for each cluster as defined by the colors dictionary.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Import the pyplot class
____

# Define a colors dictionary for clusters
colors = {____:'red', ____:'blue'}

# Plot a scatter plot
comic_con.plot.scatter(x=____, 
                	   y=____,
                	   c=comic_con['cluster_labels'].apply(____))
plt.show()
Kodu Düzenle ve Çalıştır