Clustering data with the density-based method

As an alternative to distance measurement, we can use density-based measurement to cluster data. This method finds area with a higher density than the remaining area. One of the most famous methods is DBSCAN. In the following recipe, we demonstrate how to use DBSCAN to perform density-based clustering.

Getting ready

In this recipe, we will continue to use the hotel location dataset as the input data source to perform DBSCAN clustering.

How to do it…

Please perform the following steps to perform density-based clustering:

  1. First, install and load the dbscan packages:
    > install.packages("dbscan")
    > library(dbscan)
    
  2. Cluster data in regard to its density measurement:
    > fit <- dbscan(hotel.dist, eps = 0.01, minPts ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.