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.pyplotasplt. - Assign column
0ofnew_pointstoxs, and column1ofnew_pointstoys. - Make a scatter plot of
xsandys, specifying thec=labelskeyword 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
0ofcentroidstocentroids_x, and column1ofcentroidstocentroids_y. - Make a scatter plot of
centroids_xandcentroids_y, using'D'(a diamond) as a marker by specifying themarkerparameter. Set the size of the markers to be50usings=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()