Recognizing digits using the density-based clustering method

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.

Getting ready

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.

How to do it…

Perform the following steps to cluster digits with different clustering techniques:

  1. First, install and load the png package:
    > install.packages("png")
    > library(png)
    
  2. Read images from handwriting.png and transform the read data into a scatterplot:
    > img2 = readPNG("handwriting.png", TRUE)
    > img3 ...

Get R for Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.