We have already covered density-based clustering methods, which are good at handling data without a certain shape. In this recipe, we demonstrate how to use DBSCAN to recognize digits.
In this recipe, we use handwritten digits as clustering input. You can find the figure on the author's GitHub page at https://github.com/ywchiu/rcookbook/raw/master/chapter12/handwriting.png.
Perform the following steps to cluster digits with different clustering techniques:
First, install and load the
png
package:> install.packages("png") > library(png)
Read images from
handwriting.png
and transform the read data into a scatterplot:> img2 = readPNG("handwriting.png", TRUE) > img3 = img2[,nrow(img2):1] > b = cbind(as.integer(which(img3 < -1) %% 28), which(img3 < -1) / 28) > plot(b, xlim=c(1,28), ylim=c(1,28))
Perform the k-means clustering method on the...