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.
Este exercício faz parte do curso
Unsupervised Learning in R
Instruções do exercício
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
col
argument to thecluster
component inkm.out
. - Title the plot
"k-means with 3 clusters"
using themain
argument toplot()
. - Ensure there are no axis labels by specifying
""
for both thexlab
andylab
arguments toplot()
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Scatter plot of x