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
Exercise instructions
- Import
matplotlib.pyplot
asplt
. - Assign column
0
ofnew_points
toxs
, and column1
ofnew_points
toys
. - Make a scatter plot of
xs
andys
, specifying thec=labels
keyword arguments to color the points by their cluster label. Also specifyalpha=0.5
. - Compute the coordinates of the centroids using the
.cluster_centers_
attribute ofmodel
. - Assign column
0
ofcentroids
tocentroids_x
, and column1
ofcentroids
tocentroids_y
. - Make a scatter plot of
centroids_x
andcentroids_y
, using'D'
(a diamond) as a marker by specifying themarker
parameter. Set the size of the markers to be50
usings=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()