A dissimilarity matrix can be used as a measurement for the quality of a cluster. To visualize the matrix, we can use a heat map on a distance matrix. Within the plot, entries with low dissimilarity (or high similarity) are plotted darker, which is helpful to identify hidden structures in the data. In this recipe, we will discuss some techniques that are useful for visualizing a dissimilarity matrix.
In order to visualize the dissimilarity matrix, you need to have the previous recipe completed by generating the customer dataset. In addition to this, a k-means object needs to be generated and stored in the km
variable.
Perform the following steps to visualize the dissimilarity matrix:
- First, install and load the
seriation
package:
> install.packages("seriation")
> library(seriation)
- You can then use
dissplot
to visualize the dissimilarity matrix in a heat map:
> dissplot(dist(customer), labels=km$cluster...