Clustering data with the density-based method
As an alternative to distance measurement, you can use a density-based measurement to cluster data. This method finds an area with a higher density than the remaining area. One of the most famous methods is DBSCAN. In the following recipe, we will demonstrate how to use DBSCAN to perform density-based clustering.
Getting ready
In this recipe, we will use simulated data generated from the mlbench
package.
How to do it...
Perform the following steps to perform density-based clustering:
- First, install and load the
fpc
andmlbench
packages:
> install.packages("mlbench") > library(mlbench) > install.packages("fpc") > library(fpc)
- You can then use the
mlbench
library to draw a Cassini problem graph:
> set.seed(2) > p = mlbench.cassini(500) > plot(p$x)
![](https://static.packt-cdn.com/products/9781787284395/graphics/b924aebd-4533-4eeb-a99a-38dbad30b45d.png)
The Cassini problem graph
- Next, you can cluster data with regard to its density measurement:
> ds = dbscan(dist(p$x),0...