Dbscan: Fast Density-Based Clustering With R: Michael Hahsler Matthew Piekenbrock
Dbscan: Fast Density-Based Clustering With R: Michael Hahsler Matthew Piekenbrock
Derek Doran
Wright State University
Abstract
This article describes the implementation and use of the R package dbscan, which
provides complete and fast implementations of the popular density-based clustering al-
gorithm DBSCAN and the augmented ordering algorithm OPTICS. Compared to other
implementations, dbscan offers open-source implementations using C++ and advanced
data structures like k-d trees to speed up computation. An important advantage of this
implementation is that it is up-to-date with several primary advancements that have been
added since their original publications, including artifact corrections and dendrogram ex-
traction methods for OPTICS. Experiments with dbscan’s implementation of DBSCAN
and OPTICS compared and other libraries such as FPC, ELKI, WEKA, PyClustering,
SciKit-Learn and SPMF suggest that dbscan provides a very efficient implementation.
1. Introduction
Clustering is typically described as the process of finding structure in data by grouping sim-
ilar objects together, where the resulting set of groups are called clusters. Many clustering
algorithms directly apply the idea that clusters can be formed such that objects in the same
cluster should be more similar to each other than to objects in other clusters. The notion
of similarity (or distance) stems from the fact that objects are assumed to be data points
embedded in a data space in which a similarity measure can be defined. Examples are meth-
ods based on solving the k-means problem or mixture models which find the parameters of a
parametric generative probabilistic model from which the observed data are assumed to arise.
Another approach is hierarchical clustering, which uses local heuristics to form a hierarchy of
nested grouping of objects. Most of these approaches (with the notable exception of single-
link hierarchical clustering) are biased towards clusters with convex, hyper-spherical shape. A
detailed review of these clustering algorithms is provided in Kaufman and Rousseeuw (1990),
Jain, Murty, and Flynn (1999), and the more recent review by Aggarwal and Reddy (2013).
Density-based clustering approaches clustering differently. It simply posits that clusters are
contiguous ‘dense’ regions in the data space (i.e., regions of high point density), separated by
areas of low point density (Kriegel, Kröger, Sander, and Arthur 2011; Sander 2011). Density-
based methods find such high-density regions representing clusters of arbitrary shape and
2 dbscan: Density-based Clustering with R
typically have a structured means of identifying noise points in low-density regions. These
properties provide advantages for many applications compared to other clustering approaches.
For example, geospatial data may be fraught with noisy data points due to estimation errors
in GPS-enabled sensors (Chen, Ji, and Wang 2014) and may have unique cluster shapes
caused by the physical space the data was captured in. Density-based clustering is also a
promising approach to clustering high-dimensional data (Kailing, Kriegel, and Kröger 2004),
where partitions are difficult to discover, and where the physical shape constraints assumed
by model-based methods are more likely to be violated.
Several density-based clustering algorithms have been proposed, including DBSCAN algo-
rithm (Ester, Kriegel, Sander, Xu et al. 1996), DENCLUE (Hinneburg and Keim 1998) and
many DBSCAN derivates like HDBSCAN (Campello, Moulavi, Zimek, and Sander 2015).
These clustering algorithms are widely used in practice with applications ranging from find-
ing outliers in datasets for fraud prevention (Breunig, Kriegel, Ng, and Sander 2000), to
finding patterns in streaming data (Chen and Tu 2007; Cao, Ester, Qian, and Zhou 2006),
noisy signals (Kriegel and Pfeifle 2005; Ester et al. 1996; Tran, Wehrens, and Buydens 2006;
Hinneburg and Keim 1998; Duan, Xu, Guo, Lee, and Yan 2007), gene expression data (Jiang,
Pei, and Zhang 2003), multimedia databases (Kisilevich, Mansmann, and Keim 2010), and
road traffic (Li, Han, Lee, and Gonzalez 2007).
This paper focuses on an efficient implementation of the DBSCAN algorithm (Ester et al.
1996), one of the most popular density-based clustering algorithms, whose consistent use
earned it the SIGKDD 2014’s Test of Time Award (SIGKDD 2014), and OPTICS (Ankerst,
Breunig, Kriegel, and Sander 1999), often referred to as an extension of DBSCAN. While
surveying software tools that implement various density-based clustering algorithms, it was
discovered that in a large number of statistical tools, not only do implementations vary sig-
nificantly in performance (Kriegel, Schubert, and Zimek 2016), but may also lack important
components and corrections. Specifically, for the statistical computing environment R (Team
et al. 2013), only naive DBSCAN implementations without speed-up with spatial data struc-
tures are available (e.g., in the well-known Flexible Procedures for Clustering package (Hennig
2015)), and OPTICS is not available. This motivated the development of a R package for
density-based clustering with DBSCAN and related algorithms called dbscan. The dbscan
package contains complete, correct and fast implementations of DBSCAN and OPTICS. The
package currently enjoys thousands of new installations from the CRAN repository every
month.
This article presents an overview of the R package dbscan focusing on DBSCAN and OPTICS,
outlining its operation and experimentally compares its performance with implementations in
other open-source implementations. We first review the concept of density-based clustering
and present the DBSCAN and OPTICS algorithms in Section 2. This section concludes with
a short review of existing software packages that implement these algorithms. Details about
dbscan, with examples of its use, are presented in Section 3. A performance evaluation is
presented in Section 4. Concluding remarks are offered in Section 5.
2. Density-based clustering
Density-based clustering is now a well-studied field. Conceptually, the idea behind density-
based clustering is simple: given a set of data points, define a structure that accurately reflects
Michael Hahsler, Matthew Piekenbrock, Derek Doran 3
the underlying density (Sander 2011). An important distinction between density-based clus-
tering and alternative approaches to cluster analysis, such as the use of (Gaussian) mixture
models (see Jain et al. 1999), is that the latter represents a parametric approach in which
the observed data are assumed to have been produced by mixture of either Gaussian or other
parametric families of distributions. While certainly useful in many applications, parametric
approaches naturally assume clusters will exhibit some type convex (generally hyper-spherical
or hyper-elliptical) shape. Other approaches, such as k-means clustering (where the k pa-
rameter signifies the user-specified number of clusters to find), share this common theme of
‘minimum variance’, where the underlying assumption is made that ideal clusters are found by
minimizing some measure of intra-cluster variance (often referred to as cluster cohesion) and
maximizing the inter-cluster variance (cluster separation) (Arbelaitz, Gurrutxaga, Muguerza,
Pérez, and Perona 2013). Conversely, the label density-based clustering is used for methods
which do not assume parametric distributions, are capable of finding arbitrarily-shaped clus-
ters, handle varying amounts of noise, and require no prior knowledge regarding how to set
the number of clusters k. This methodology is best expressed in the DBSCAN algorithm,
which we discuss next.
As one of the most cited of the density-based clustering algorithms (Microsoft Academic
Search 2016), DBSCAN (Ester et al. 1996) is likely the best known density-based clustering
algorithm in the scientific community today. The central idea behind DBSCAN and its
extensions and revisions is the notion that points are assigned to the same cluster if they
are density-reachable from each other. To understand this concept, we will go through the
most important definitions used in DBSCAN and related algorithms. The definitions and the
presented pseudo code follows the original by Ester et al. (1996), but are adapted to provide
a more consistent presentation with the other algorithms discussed in the paper.
Clustering starts with a dataset D containing a set of points p ∈ D. Density-based algorithms
need to obtain a density estimate over the data space. DBSCAN estimates the density around
a point using the concept of ǫ-neighborhood.
Definition 1. ǫ-Neighborhood. The ǫ-neighborhood, Nǫ (p), of a data point p is the set of
points within a specified radius ǫ around p.
Following this definition, the size of the neighborhood |Nǫ (p)| can be seen as a simple un-
normalized kernel density estimate around p using a uniform kernel and a bandwidth of ǫ.
DBSCAN uses Nǫ (p) and a threshold called minPts to detect dense regions and to classify
the points in a data set into core, border, or noise points.
Definition 2. Point classes. A point p ∈ D is classified as
❼ a core point if Nǫ (p) has high density, i.e., |Nǫ (p)| ≥ minPts where minPts ∈ Z+ is a
user-specified density threshold,
4 dbscan: Density-based Clustering with R
(a) (b)
Figure 1: Concepts used the DBSCAN family of algorithms. (a) shows examples for the three
point classes, core, border, and noise points, (b) illustrates the concept of density-reachability
and density-connectivity.
❼ a border point if p is not a core point, but it is in the neighborhood of a core point
q ∈ D, i.e., p ∈ Nǫ (q), or
A visual example is shown in Figure 1(a). The size of the neighborhood for some points is
shown as a circle and their class is shown as an annotation.
To form contiguous dense regions from individual points, DBSCAN defines the notions of
reachability and connectedness.
2. q ∈ Nǫ (p).
The notion of density-connection can be used to form clusters as contiguous dense regions.
2. Connectivity: ∀ p, q ∈ C, p is density-connected to q.
The DBSCAN algorithm identifies all such clusters by finding all core points and expanding
each to all density-reachable points. The algorithm begins with an arbitrary point p and
retrieves its ǫ-neighborhood. If it is a core point then it will start a new cluster that is
expanded by assigning all points in its neighborhood to the cluster. If an additional core
point is found in the neighborhood, then the search is expanded to include also all points in
its neighborhood. If no more core points are found in the expanded neighborhood, then the
cluster is complete and the remaining points are searched to see if another core point can be
found to start a new cluster. After processing all points, points which were not assigned to a
cluster are considered noise.
In the DBSCAN algorithm, core points are always part of the same cluster, independent
of the order in which the points in the dataset are processed. This is different for border
points. Border points might be density-reachable from core points in several clusters and the
algorithm assigns them to the first of these clusters processed which depends on the order
of the data points and the particular implementation of the algorithm. To alleviate this
behavior, Campello et al. (2015) suggest a modification called DBSCAN* which considers all
border points as noise instead and leaves them unassigned.
Reachability Plot
0.12
Reachability dist.
0.08
0.04
Order
Figure 2: OPTICS reachability plot example for a data set with four clusters of 100 data
points each.
where minPts-dist(p) is the distance from p to its minPts − 1 nearest neighbor, i.e., the
minimal radius a neighborhood of size minPts centered at and including p would have.
Definition 8. Reachability-distance. The reachability-distance of a point p ∈ D to a point
q ∈ D parameterized by ǫ and minPts is defined as
(
UNDEFINED if |Nǫ (p)| < minPts, and
reachability-dist(p, q; ǫ, minPts) =
max(core-dist(p), d(p, q)) otherwise.
The reachability-distance of a core point p with respect to object q is the smallest neighbor-
hood radius such that p would be directly density-reachable from q. Note that ǫ is typically
set very large compared to DBSCAN. Therefore, minPts behaves differently for OPTICS:
more points will be considered core points and it affects how many nearest neighbors are
considered in the core-distance calculation, where larger values will lead to larger and more
smooth reachability distributions. This needs to be kept in mind when choosing appropriate
parameters.
OPTICS provides an augmented ordering. The algorithm starting with a point and expands
it’s neighborhood like DBSCAN, but it explores the new point in the order of lowest to high-
est core-distance. The order in which the points are explored along with each point’s core-
and reachability-distance is the final result of the algorithm. An example of the order and
the resulting reachability-distance is shown in the form of a reachability plot in Figure 2.
Low reachability-distances shown as valleys represent clusters separated by peaks represent-
ing points with larger distances. This density representation essentially conveys the same
information as the often used dendrogram or ‘tree-like’ structure. This is why OPTICS is
often also noted as a visualization tool. Sander, Qin, Lu, Niu, and Kovarsky (2003) showed
how the output of OPTICS can be converted into an equivalent dendrogram, and that under
certain conditions, the dendrogram produced by the well known hierarchical clustering with
single linkage is identical to running OPTICS with the parameter minPts = 2
From the order discovered by OPTICS, two ways to group points into clusters was discussed
in Ankerst et al. (1999), one which we will refer to as the ExtractDBSCAN method and
Michael Hahsler, Matthew Piekenbrock, Derek Doran 7
2. Extract-ξ identifies clusters hierarchically by scanning through the ordering that OP-
TICS produces to identify significant, relative changes in reachability-distance. The
authors of OPTICS noted that clusters can be thought of as identifying ‘dents’ in the
reachability plot.
The first argument x is the data set in form of a data.frame or a matrix. The implemen-
tations use by default Euclidean distance for neighborhood computation. Alternatively, a
precomputed set of pair-wise distances between data points stored in a dist object can be
supplied. Using precomputed distances, arbitrary distance metrics can be used, however, note
that k-d trees are not used for distance data, but lists of nearest neighbors are precomputed.
For dbscan() and optics(), the parameter eps represents the radius of the ǫ-neighborhood
considered for density estimation and minPts represents the density threshold to identify core
points. Note that eps is not strictly necessary for OPTICS but is only used as an upper limit
for the considered neighborhood size used to reduce computational complexity. dbscan() also
can use weights for the data points in x. The density in a neighborhood is just the sum of
the weights of the points inside the neighborhood. By default, each data point has a weight
of one, so the density estimate for the neighborhood is just the number of data points inside
the neighborhood. Using weights, the importance of points can be changed.
The original DBSCAN implementation assigns border points to the first cluster it is density
reachable from. Since this may result in different clustering results if the data points are
processed in a different order, Campello et al. (2015) suggest for DBSCAN* to consider
border points as noise. This can be achieved by using borderPoints = FALSE. All functions
accept additional arguments. These arguments are passed on to the fixed-radius nearest
neighbor search. More details about the implementation of the nearest neighbor search will
be presented in Section 3.1 below.
Clusters can be extracted from the linear order produced by OPTICS. The dbscan implemen-
tation of the cluster extraction methods for ExtractDBSCAN and Extract-ξ are:
extractDBSCAN(object, eps_cl)
extractXi(object, xi, minimum = FALSE, correctPredecessor = TRUE)
The interfaces only differ in the way that kNN() requires to specify k while frNN() needs
the radius eps. All other arguments are the same. x is the data and the result will be a
list of neighbors in x for each point in x. sort controls if the returned points are sorted by
distance. search controls what searching method should be used. Available search meth-
ods are "kdtree", "linear" and "dist". The linear search method does not build a search
data structure, but performs a complete linear search to find the nearest neighbors. The dist
method precomputes a dissimilarity matrix which is very fast for small data sets, but prob-
lematic for large sets. The default method is to build a k-d tree. k-d trees are implemented
in C++ using a modified version of the ANN library (Mount and Arya 2010) compiled for
Euclidean distances. Parameters bucketSize, splitRule and approx are algorithmic pa-
rameters which control the way the k-d tree is built. bucketSize controls the maximal size
of the k-d tree leaf nodes. splitRule specifies the method how the k-d tree partitions the
data space. We use "suggest", which uses the best guess of the ANN library given the
data. approx greater than zero uses approximate NN search. Only nearest neighbors up to
a distance of a factor of (1 + approx)eps will be returned, but some actual neighbors may
be omitted potentially leading to spurious clusters and noise points. However, the algorithm
will enjoy a significant speedup. For more details, we refer the reader to the documentation
of the ANN library (Mount and Arya 2010). dbscan() and optics() use internally frNN()
and the additional arguments in ... are passed on to the nearest neighbor search method.
Michael Hahsler, Matthew Piekenbrock, Derek Doran 11
1.0
0.8
0.6
y
0.4
●
●
●● ●●
●
● ● ●● ●● ● ●
●●●●●● ● ●●● ●● ●● ●
●●● ●
0.2
●
● ● ● ● ●● ● ● ●
●●●● ● ●
●
● ● ●●●● ●
●●●● ●●●
● ● ●● ●
● ●● ●● ●● ● ● ●
● ● ● ● ●● ●●
0.0
● ● ●
●● ●
●
Figure 3: The sample dataset, consisting of 4 noisy Gaussian distributions with slight overlap.
3.2. Clustering with DBSCAN
We use a very simple artificial data set of four slightly overlapping Gaussians in two-dimensional
space with 100 points each. We load dbscan, set the random number generator to make the
results reproducible and create the data set.
> library("dbscan")
> set.seed(2)
> n <- 400
> x <- cbind(
+ x = runif(4, 0, 1) + rnorm(n, sd = 0.1),
+ y = runif(4, 0, 1) + rnorm(n, sd = 0.1)
+ )
> true_clusters <- rep(1:4, time = 100)
> kNNdistplot(x, k = 3)
> abline(h=.05, col = "red", lty=2)
12 dbscan: Density-based Clustering with R
0.15
3−NN distance
0.10
0.05
0.00
0 1 2 3 4 5 6
30 185 87 89 3 3 3
The resulting clustering identified one large cluster with 185 member points and 2 medium size
clusters of between 87 and 89 points, three very small clusters and 30 noise points (represented
by cluster id 0). The available fields can be directly accessed using the list extraction operator
$. For example, the cluster assignment information can be used to plot the data with the
clusters identified by different labels and colors.
The scatter plot in Figure 5 shows that the clustering algorithm correctly identified the upper
two clusters, but merged the lower two clusters because the region between them has a high
enough density. The small clusters are isolated groups of 3 points (passing minPts) and the
noise points isolated points. dbscan also provides a plot that adds convex cluster hulls to the
scatter plot shown in Figure 6.
● ●
1.0
●
● ●
●
●
0.8
● ●
●
●
0.6
●
●
y
●
0.4
● ●
● ●
● ●●
●
0.2
● ●
0.0
●● ●
●
●
●
● ● ●
● ●
●
1.0
● ●
●● ●
● ● ●●
●
●● ●
● ● ●
● ●●●
●● ●
● ● ●●
● ●●● ● ●● ● ●
● ●
●● ●
● ● ● ●●
● ● ● ●● ●
● ● ● ● ● ●
● ●
0.8
● ● ●
● ● ● ● ●
● ●
● ● ● ● ●
●
● ●● ● ● ● ●
● ● ● ● ●●● ● ●
● ● ● ●
●
●
● ● ●
● ● ● ●
● ●
● ● ●
● ● ● ●● ● ●
●● ●● ●●
0.6
● ●●
● ● ●● ●● ●
●● ● ● ●●● ● ●
● ● ●
● ●● ● ● ●● ●
● ● ● ● ●
● ● ●● ● ●
●
● ● ● ● ●● ●
● ●
y
● ● ●
● ●● ● ●
● ●
● ●● ●
●
0.4
●
●● ●
● ● ●
●
● ● ●●
● ● ● ● ●
●
● ● ● ● ● ●
● ● ● ● ●● ●
● ● ●
● ● ● ●●
● ● ● ● ● ● ● ●
● ● ● ● ●
● ● ●● ● ● ● ● ● ●
● ● ● ●
0.2
● ● ●● ● ● ●● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ●●
● ● ●● ●● ● ● ●
● ● ● ● ● ●● ● ●
● ● ● ● ●
● ●●● ● ● ●● ●
● ● ●●●
●●
●
● ● ●●
●
● ● ●● ●● ● ● ●● ●
● ● ● ●● ●
●
●● ●● ● ● ● ●
● ●
● ● ● ● ●
● ● ● ●
●● ● ● ●
● ● ● ● ●● ● ●
● ●
0.0
● ● ● ●
● ● ● ●
●
● ●
● ●
Figure 6: Convex hull plot of the DBSCAN clustering. Noise points are black. Note that
noise points and points of another cluster may lie within the convex hull of a different cluster.
14 dbscan: Density-based Clustering with R
A clustering can also be used to find out to which clusters new data points would be assigned
using predict(object, newdata = NULL, data, ...). The predict method uses nearest
neighbor assignment to core points and needs the original dataset. Additional parameters are
passed on to the nearest neighbor search method. Here we obtain the cluster assignment for
the first 25 data points. Note that an assignment to cluster 0 means that the data point is
considered noise because it is not close enough to a core point.
[1] 1 2 1 0 1 2 1 3 1 2 1 3 1 0 1 3 1 2 0 3 1 2 1 3 1
OPTICS is an augmented ordering algorithm, which stores the computed order of the points
it found in the order element of the returned object.
[1] 1 363 209 349 337 301 357 333 321 285 281 253 241 177 153
This means that data point 1 in the data set is the first in the order, data point 363 is the
second and so forth. The density-based order produced by OPTICS can be directly plotted
as a reachability plot.
> plot(res)
The reachability plot in Figure 7 shows the reachability distance for points ordered by OP-
TICS. Valleys represent potential clusters separated by peaks. Very high peaks may indicate
noise points. To visualize the order on the original data sets we can plot a line connecting
the points in order.
Michael Hahsler, Matthew Piekenbrock, Derek Doran 15
Reachability Plot
0.12
Reachability dist.
0.08
0.04
Order
Figure 7: OPTICS reachability plot. Note that the first reachability value is always UNDE-
FINED.
● ● ●
● ● ●
●
1.0
●●
● ●
●
● ● ● ●
●●● ●●
●● ●●
● ●● ●●● ●
●
●
●
● ●●●●
● ● ●● ●
●
● ● ● ● ●
● ●● ● ● ●●● ●●●●●● ●● ●
0.8
● ● ●● ●●●
● ● ●● ● ●● ●
● ●● ● ●●●
●● ● ● ● ●●
● ● ● ●●
● ●●
● ●● ●
● ● ●● ● ●●● ●
● ●●● ●●●
● ●
●● ●●
0.6
● ● ●●● ●
●
●●●● ● ● ●
●●●● ● ● ● ●● ● ●
● ●●●● ● ● ●● ●
● ● ● ●● ● ●● ●● ●
● ● ●
y
● ●● ●● ● ●
● ● ●● ●
●
0.4
●● ● ●
● ●●
● ●● ● ● ● ●●● ●● ●
●● ● ●● ● ●●●●●
●●
● ●
● ● ● ●● ●● ● ● ●
● ●
●●●●●● ● ● ●● ● ● ● ●
● ●●
● ● ● ● ●●
●●● ● ●● ● ●●● ●● ●● ● ● ●●
0.2
● ●●●● ● ● ●●●●
● ●
● ● ●● ● ●
● ● ● ● ● ●● ●
●
●●●● ●● ● ● ●
●●● ●● ● ●●●●
●
●●●●● ● ●●●● ● ●● ●
●● ●● ●
●
●●● ●
● ● ● ●
● ●● ●● ●● ● ●● ●
● ● ● ● ●● ●● ● ●
0.0
● ● ●● ●
●● ● ●
●
Figure 8 shows that points in each cluster are visited in consecutive order starting with the
points in the center (the densest region) and then the points in the surrounding area.
As noted in Section 2.2, OPTICS has two primary cluster extraction methods using the
ordered reachability structure it produces. A DBSCAN-type clustering can be extracted
using extractDBSCAN() by specifying the global eps parameter. The reachability plot in
figure 7 shows four peaks, i.e., points with a high reachability-distance. These points indicate
boundaries between clusters four clusters. An eps threshold that separates the four clusters
can be visually determined. In this case we use eps_cl of 0.065.
The resulting reachability and corresponding clusters are shown in Figures 9 and 10. The
clustering resembles closely the original structure of the four clusters with which the data were
generated, with the only difference that points on the boundary of the clusters are marked as
noise points.
dbscan also provides extractXi() to extract a hierarchical cluster structure. We use here a
xi value of 0.05.
The ξ method results in a hierarchical clustering structure, and thus points can be members
of several nested clusters. Clusters are represented as contiguous ranges in the reachability
plot and are available the field clusters_xi.
> res$clusters_xi
Reachability Plot
0.12
Reachability dist.
0.08
0.04
Order
●
● ●
● ● ●
●
1.0
● ● ● ●
●● ● ●●
●
● ●
● ●
● ●
● ●●●●● ●
● ●●
●
● ● ●● ● ● ●
●
●● ● ●●
● ●●
● ● ●
● ● ● ● ●
● ●
● ● ● ● ●
● ●
● ● ●
0.8
● ● ●
● ●
● ●
● ● ●
● ●● ● ●
● ● ●
● ● ●
● ● ● ● ●
● ● ●●●
● ● ●
●● ● ●
● ● ●
●
● ●
●
● ● ● ● ● ●
● ● ● ●
●●
● ●● ●
●●
0.6
● ● ● ● ●● ●
●
●● ● ● ●● ● ● ● ●
● ● ● ● ●
● ● ● ●
● ● ●
● ● ● ● ●● ●
● ● ● ●
● ● ● ●
● ●
●
y
● ● ●
● ● ●
●● ● ●
●● ●
● ●
●
0.4
●●
●
● ● ●
●
● ● ● ● ● ●
● ● ● ●
● ● ● ● ●
● ● ●
● ● ● ●●
● ● ●
● ● ● ●●
● ● ● ● ●●
● ● ● ● ● ●
●
● ● ●
●● ● ● ● ● ● ●
● ● ● ● ● ●●
● ●● ●
0.2
● ●● ●
● ● ● ● ● ● ● ● ●●
● ● ● ●● ● ● ●
● ●
●
●
● ● ● ●
● ● ● ●● ● ● ● ●
● ● ● ● ●● ● ●
●●● ● ● ● ●
● ● ● ● ●
● ● ●● ● ● ● ●
● ● ●● ● ● ● ●
● ● ● ●
●● ● ●
●
● ●
●
● ● ● ● ●
●
● ●
● ● ● ●
● ● ● ● ● ●● ● ●
●
●
● ● ● ●● ●
●
●
0.0
● ● ●
●
●
● ●
● ●
Figure 10: Convex hull plot for a DBSCAN-type clustering extracted at global ǫ = 0.065
results in four clusters.
18 dbscan: Density-based Clustering with R
Here we have seven clusters. The clusters are also visible in the reachability plot.
> plot(res)
Figure 11 shows the reachability plot with clusters represented using colors and vertical bars
below the plot. The clusters themselves can also be plotted with the convex hull plot function
shown in Figure 12. Note how the nested structure is shown by clusters inside of clusters.
Also note that it is possible for the convex hull, while useful for visualizations, to contain a
point that is not considered as part of a cluster grouping.
Note how the dendrogram in Figure 13 closely resembles the reachability plots with added
binary splits. Since the object is a standard dendrogram (from package stats), it can be used
like any other dendrogram created with hierarchical clustering.
4. Performance Comparison
Finally, we evaluate the performance of dbscan’s implementation of DBSCAN and OPTICS
against other open-source implementations. This is not a comprehensive evaluation study, but
is used to demonstrate the performance of dbscan’s DBSCAN and OPTICS implementation
on datasets of varying sizes as compared to other software packages. A comparative test was
performed using both DBSCAN and OPTICS algorithms, where supported, for the libraries
listed in Table 1 on page 8. The used datasets and their sizes are listed in Table 2. The
data sets tested include s1 and s2, the randomly generated but moderately-separated Gaus-
sian clusters often used for agglomerative cluster analysis (Fränti and Virmajoki 2006), the
R15 validation data set used for maximum variance based clustering approach by Veenman,
Reinders, and Backer (2002), the well-known spatial data set t4.8k used for validation of the
Michael Hahsler, Matthew Piekenbrock, Derek Doran 19
Reachability Plot
0.12
Reachability dist.
0.08
0.04
0.00
●
● ● ●
● ●
●
1.0
● ●
●● ●
● ● ●●
●
●● ●
● ● ●
● ●●●
●● ●
● ● ●●
● ●
●● ● ● ●
●
●● ● ●●
● ● ● ●●
● ●
●
● ● ●● ● ●
● ● ● ● ● ●
0.8
● ● ●
● ● ● ● ●
● ● ●
● ● ● ● ●
● ●● ● ● ● ●
● ● ● ● ●●● ● ●
● ● ● ●
●
●
● ● ●
● ● ● ●
● ●
● ● ●
● ● ● ●● ● ●
●● ●● ●●
0.6
● ●●
● ● ●● ●● ●
●
● ● ● ●● ● ● ● ●
● ● ●
● ●● ● ● ● ●
● ● ● ● ●
● ● ●● ● ●
●
● ● ● ● ●● ●
● ●
y
● ● ●
● ●● ● ●
● ●
● ●● ●
●
0.4
●
●● ●
● ● ●
●
● ●
● ● ● ●● ●
● ●
● ● ● ● ● ●
● ● ● ● ●● ●
● ● ●
● ● ● ●●
● ● ● ● ● ● ● ● ● ●
● ● ● ●
● ● ●● ● ● ● ● ● ● ●
● ●
0.2
● ● ●● ● ● ●● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ●●
● ● ●●●● ● ● ●
● ● ● ● ● ●● ● ●
● ●
● ● ● ● ●● ●
● ●● ● ● ●● ● ● ●
● ● ● ●● ●●
●
● ● ●● ●● ● ● ●● ●
● ● ● ●● ●
●
●● ●● ● ● ● ●
● ●
● ● ● ● ●
●
● ●● ●● ●
● ●
● ● ● ● ●● ●
● ● ●
0.0
● ● ● ●
● ● ● ●
●
● ●
● ●
Figure 12: Convex hull plot of a hierarchical clustering extracted with Extract-ξ.
20 dbscan: Density-based Clustering with R
0.12
Reachability dist.
0.08
0.04
0.00
CHAMELEON algorithm (Karypis, Han, and Kumar 1999), along with a variety of shape
data sets commonly found in clustering validation papers (Gionis, Mannila, and Tsaparas
2007; Zahn 1971; Chang and Yeung 2008; Jain and Martin 2005; Fu and Medico 2007).
We performed the comparison with ELKI version 0.7, PyClustering 0.6.6, fpc 2.1-10, dbscan
0.9-8, SPMF v2.10, WEKA 3.8.0, SciKit-Learn 0.17.1 on a MacBook Pro equipped with an
2.5 GHz Intel Core i7 processor, running OS X El Capitan 10.11.6. All data sets where
normalized to the unit interval, [0, 1], per dimension to standardize neighbor queries. For
all data sets we used minPts = 2 and ǫ = 0.10 for DBSCAN. For OPTICS, minPts = 2
with a large ǫ = 1 was used. We replicated each run for each data set 15 times and report
the average runtime here. Figures 14 and 15 shows the runtimes. The datasets are sorted
from easiest to hardest and the algorithm in the legend are sorted from on average fastest to
slowest. The results show that the implementation in dbscan compares very favorably to the
other implementations.
5. Concluding Remarks
The dbscan package offers a set of scalable, robust, and complete implementations of popular
density-based clustering algorithms from the DBSCAN family. The main features of dbscan
are a simple interface to fast clustering and cluster extraction algorithms, extensible data
structures and methods for both density-based clustering visualization and representation
including efficient conversion algorithms between OPTICS ordering and dendrograms. In
addition to DBSCAN and OPTICS discussed in this paper, dbscan also contains a fast version
of the local outlier factor (LOF) algorithm (Breunig et al. 2000) and an implementation of
HDBSCAN (Campello et al. 2015) is under development.
Michael Hahsler, Matthew Piekenbrock, Derek Doran 21
DBSCAN Benchmarks
Log scale
Library
dbscan
1000 spmf
Time (ms)
scikit
elki
10 weka
fpc
pycluster
pathbased
spiral
flame
jain
Compound
R15
Aggregation
synth1
synth2
D31
synth3
s1
s4
t4.8k
Dataset
Figure 14: Runtime of DBSCAN in milliseconds (y-axis, logarithmic scale) vs. the name of
the data set tested (x-axis).
22 dbscan: Density-based Clustering with R
OPTICS Benchmarks
Log scale
Library
10000 dbscan
Time (ms)
elki
weka
100 spmf
pycluster
pathbased
spiral
flame
jain
Compound
R15
Aggregation
synth2
synth1
synth3
D31
s1
s4
t4.8k
Dataset
Figure 15: Runtime of OPTICS in milliseconds (y-axis, logarithmic scale) vs. the name of
the data set tested (x-axis).
6. Acknowledgments
This work is partially supported by industrial and government partners at the Center for
Surveillance Research, a National Science Foundation I/UCRC.
References
Aggarwal CC, Reddy CK (2013). Data Clustering: Algorithms and Applications. 1st edition.
Chapman & Hall/CRC. ISBN 1466558210, 9781466558212.
Ankerst M, Breunig MM, Kriegel HP, Sander J (1999). “OPTICS: ordering points to identify
the clustering structure.” In ACM Sigmod Record, volume 28, pp. 49–60. ACM.
Arbelaitz O, Gurrutxaga I, Muguerza J, Pérez JM, Perona I (2013). “An extensive comparative
study of cluster validity indices.” Pattern Recognition, 46(1), 243–256.
Bentley JL (1975). “Multidimensional binary search trees used for associative searching.”
Communications of the ACM, 18(9), 509–517.
Birant D, Kut A (2007). “ST-DBSCAN: An algorithm for clustering spatial–temporal data.”
Data & Knowledge Engineering, 60(1), 208–221.
Breunig MM, Kriegel HP, Ng RT, Sander J (2000). “LOF: identifying density-based local
outliers.” In ACM sigmod record, volume 29, pp. 93–104. ACM.
Campello RJ, Moulavi D, Zimek A, Sander J (2015). “Hierarchical density estimates for
data clustering, visualization, and outlier detection.” ACM Transactions on Knowledge
Discovery from Data (TKDD), 10(1), 5.
Cao F, Ester M, Qian W, Zhou A (2006). “Density-Based Clustering over an Evolving Data
Stream with Noise.” In SDM, volume 6, pp. 328–339. SIAM.
Michael Hahsler, Matthew Piekenbrock, Derek Doran 23
Celebi ME, Aslandogan YA, Bergstresser PR (2005). “Mining biomedical images with density-
based clustering.” In International Conference on Information Technology: Coding and
Computing (ITCC’05)-Volume II, volume 1, pp. 163–168. IEEE.
Chowdhury AMR, Mollah ME, Rahman MA (2010). “An efficient method for subjectively
choosing parameter ‘k’automatically in VDBSCAN (Varied Density Based Spatial Clus-
tering of Applications with Noise) algorithm.” In Computer and Automation Engineering
(ICCAE), 2010 The 2nd International Conference on, volume 1, pp. 38–41. IEEE.
Cormen TH, Leiserson CE, Rivest RL, Stein C (2001). “Introduction to algorithms second
edition.”
Duan L, Xu L, Guo F, Lee J, Yan B (2007). “A local-density based spatial clustering algorithm
with noise.” Information Systems, 32(7), 978–986.
Ertöz L, Steinbach M, Kumar V (2003). “Finding clusters of different sizes, shapes, and
densities in noisy, high dimensional data.” In SDM, pp. 47–58. SIAM.
Ester M, Kriegel HP, Sander J, Xu X, et al. (1996). “A density-based algorithm for discovering
clusters in large spatial databases with noise.” In Kdd, volume 96, pp. 226–231.
Fränti P, Virmajoki O (2006). “Iterative shrinking method for clustering problems.” Pattern
Recognition, 39(5), 761–765.
Fu L, Medico E (2007). “FLAME, a novel fuzzy clustering method for the analysis of DNA
microarray data.” BMC Bioinformatics, 8(1), 1.
Gupta G, Liu A, Ghosh J (2010). “Automated hierarchical density shaving: A robust auto-
mated clustering and visualization framework for large biological data sets.” IEEE/ACM
Transactions on Computational Biology and Bioinformatics, 7(2), 223–237. ISSN 15455963.
doi:10.1109/TCBB.2008.32.
Hennig C (2015). fpc: Flexible Procedures for Clustering. R package version 2.1-10, URL
https://CRAN.R-project.org/package=fpc.
Jain AK, Martin H (2005). “Law, Data clustering: a user’s dilemma.” In Proceedings of the
First international conference on Pattern Recognition and Machine Intelligence.
Jain AK, Murty MN, Flynn PJ (1999). “Data Clustering: A Review.” ACM Computuing
Surveys, 31(3), 264–323. ISSN 0360-0300. doi:10.1145/331499.331504. URL http:
//doi.acm.org/10.1145/331499.331504.
Jiang D, Pei J, Zhang A (2003). “DHC: a density-based hierarchical clustering method for
time series gene expression data.” In Bioinformatics and Bioengineering, 2003. Proceedings.
Third IEEE Symposium on, pp. 393–400. IEEE.
Kailing K, Kriegel HP, Kröger P (2004). “Density-connected subspace clustering for high-
dimensional data.” In Proc. SDM, volume 4. SIAM.
Karypis G, Han EH, Kumar V (1999). “Chameleon: Hierarchical clustering using dynamic
modeling.” Computer, 32(8), 68–75.
Kriegel HP, Kröger P, Sander J, Arthur Z (2011). “Density-based clustering.” Wires Data
and Knowledge Discovery, 1, 231–240.
Kriegel HP, Schubert E, Zimek A (2016). “The (black) art of runtime evaluation: Are we
comparing algorithms or implementations?” Knowledge and Information Systems, pp. 1–38.
Michael Hahsler, Matthew Piekenbrock, Derek Doran 25
Li X, Han J, Lee JG, Gonzalez H (2007). “Traffic density-based discovery of hot routes in road
networks.” In International Symposium on Spatial and Temporal Databases, pp. 441–459.
Springer.
Liu P, Zhou D, Wu N (2007). “VDBSCAN: varied density based spatial clustering of ap-
plications with noise.” In 2007 International conference on service systems and service
management, pp. 1–4. IEEE.
Mount DM, Arya S (2010). ANN: library for approximate nearest neighbour searching. URL
http://www.cs.umd.edu/~mount/ANN/.
Patwary MMA, Blair J, Manne F (2010). “Experiments on union-find algorithms for the
disjoint-set data structure.” In International Symposium on Experimental Algorithms, pp.
411–423. Springer.
Pei T, Jasra A, Hand DJ, Zhu AX, Zhou C (2009). “DECODE: a new method for discovering
clusters of different densities in spatial data.” Data Mining and Knowledge Discovery, 18(3),
337–369.
Rehman SU, Asghar S, Fong S, Sarasvady S (2014). “DBSCAN: Past, present and future.”
In Applications of Digital Information and Web Technologies (ICADIWT), 2014 Fifth In-
ternational Conference on the, pp. 232–238. IEEE.
Roy S, Bhattacharyya D (2005). “An approach to find embedded clusters using density
based techniques.” In International Conference on Distributed Computing and Internet
Technology, pp. 523–535. Springer.
Schubert E, Koos A, Emrich T, Züfle A, Schmid KA, Zimek A (2015). “A Framework for
Clustering Uncertain Data.” PVLDB, 8(12), 1976–1979. URL http://www.vldb.org/
pvldb/vol8/p1976-schubert.pdf.
SIGKDD (2014). “SIGKDD News : 2014 SIGKDD Test of Time Award.” http://www.kdd.
org/News/view/2014-sigkdd-test-of-time-award. (Accessed on 10/10/2016).
26 dbscan: Density-based Clustering with R
Team RC, et al. (2013). “R: A language and environment for statistical computing.”
Tran TN, Wehrens R, Buydens LM (2006). “KNN-kernel density-based clustering for high-
dimensional multivariate data.” Computational Statistics & Data Analysis, 51(2), 513–525.
Veenman CJ, Reinders MJT, Backer E (2002). “A maximum variance cluster algorithm.”
IEEE Transactions on Pattern Analysis and Machine Intelligence, 24(9), 1273–1280.
Zahn CT (1971). “Graph-theoretical methods for detecting and describing gestalt clusters.”
IEEE Transactions on computers, 100(1), 68–86.
Michael Hahsler, Matthew Piekenbrock, Derek Doran 27
Affiliation:
Michael Hahsler
Department of Engineering Management, Information, and Systems
Bobby B. Lyle School of Engineering, SMU
P. O. Box 750123, Dallas, TX 75275
E-mail: [email protected]
URL: http://michael.hahsler.net/
Matt Piekenbrock
Department of Computer Science and Engineering
Dept. of Computer Science and Engineering, Wright State University
3640 Colonel Glenn Hwy, Dayton, OH, 45435
E-mail: [email protected]
URL: http://wright.edu/
2
see https://elki-project.github.io/releases/release_notes_0.7
28 dbscan: Density-based Clustering with R
Derek Doran
Department of Computer Science and Engineering
Dept. of Computer Science and Engineering, Wright State University
3640 Colonel Glenn Hwy, Dayton, OH, 45435
E-mail: [email protected]
URL: http://knoesis.org/doran