Visualizing and interpreting results of kmeans()
One of the more intuitive ways to interpret the results of k-means models is by plotting the data as a scatter plot and using color to label the samples' cluster membership. In this exercise, you will use the standard plot() function to accomplish this.
To create a scatter plot, you can pass data with two features (i.e., columns) to plot() with an extra argument col = km.out$cluster, which sets the color of each point in the scatter plot according to its cluster membership.
This exercise is part of the course
Unsupervised Learning in R
Exercise instructions
x and km.out are available in your workspace. Using the plot() function to create a scatter plot of data x:
- Color the dots on the scatterplot by setting the
colargument to theclustercomponent inkm.out. - Title the plot
"k-means with 3 clusters"using themainargument toplot(). - Ensure there are no axis labels by specifying
""for both thexlabandylabarguments toplot().
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Scatter plot of x