LoslegenKostenlos loslegen

Untersuche dein Clustering

Schau dir nun das Clustering an, das du in der vorherigen Übung erstellt hast!

Eine Lösung der vorherigen Übung wurde bereits ausgeführt, daher ist new_points ein Array von Punkten und labels ist das Array ihrer Cluster-Labels.

Diese Übung ist Teil des Kurses

Unsupervised Learning in Python

Kurs anzeigen

Anleitung zur Übung

  • Importiere matplotlib.pyplot als plt.
  • Weise Spalte 0 von new_points xs zu und Spalte 1 von new_points ys.
  • Erstelle ein Streudiagramm von xs und ys und gib die Schlüsselwortargumente c=labels an, um die Punkte anhand ihres Cluster-Labels zu färben. Gib außerdem alpha=0.5 an.
  • Berechne die Koordinaten der Zentroiden über das Attribut .cluster_centers_ von model.
  • Weise Spalte 0 von centroids centroids_x zu und Spalte 1 von centroids centroids_y.
  • Erstelle ein Streudiagramm von centroids_x und centroids_y und verwende 'D' (eine Raute) als Marker, indem du den Parameter marker setzt. Setze die Größe der Marker mit s=50 auf 50.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Import pyplot
____

# Assign the columns of new_points: xs and ys
xs = ____
ys = ____

# Make a scatter plot of xs and ys, using labels to define the colors
____

# Assign the cluster centers: centroids
centroids = ____

# Assign the columns of centroids: centroids_x, centroids_y
centroids_x = centroids[:,0]
centroids_y = centroids[:,1]

# Make a scatter plot of centroids_x and centroids_y
____
plt.show()
Code bearbeiten und ausführen