Get startedGet started for free

Inspect your clustering

Let's now inspect the clustering you performed in the previous exercise!

A solution to the previous exercise has already run, so new_points is an array of points and labels is the array of their cluster labels.

This exercise is part of the course

Unsupervised Learning in Python

View Course

Exercise instructions

  • Import matplotlib.pyplot as plt.
  • Assign column 0 of new_points to xs, and column 1 of new_points to ys.
  • Make a scatter plot of xs and ys, specifying the c=labels keyword arguments to color the points by their cluster label. Also specify alpha=0.5.
  • Compute the coordinates of the centroids using the .cluster_centers_ attribute of model.
  • Assign column 0 of centroids to centroids_x, and column 1 of centroids to centroids_y.
  • Make a scatter plot of centroids_x and centroids_y, using 'D' (a diamond) as a marker by specifying the marker parameter. Set the size of the markers to be 50 using s=50.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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()
Edit and Run Code