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:
- First, install and load the
dbscan
packages:> install.packages("dbscan") > library(dbscan)
- Cluster data in regard to its density measurement:
> fit <- dbscan(hotel.dist, eps = 0.01, minPts = 3) > fit DBSCAN clustering for 102 objects. Parameters: eps = 0.01, minPts = 3 The clustering contains 4 cluster(s) and 3 noise points. 0 1 2 3 4 3 17 65 12 5 Available fields: cluster, eps, minPts
- Plot...