Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

dbscan

> 编程语言
Open source

Density Based Clustering of Applications with Noise (DBSCAN) and Related Algorithms - R package

350 stars0 likes1 views
WebsiteGitHub

About

Density Based Clustering of Applications with Noise (DBSCAN) and Related Algorithms - R package

R package dbscan - Density-Based Spatial Clustering of Applications with Noise (DBSCAN) and Related Algorithms

Maintainer: Michael Hahsler

Introduction

This R package (Hahsler et al. 2019) provides a fast C++ (re)implementation of several density-based algorithms with a focus on the DBSCAN family for clustering spatial data. The package includes:

Clustering

  • DBSCAN: Density-based spatial clustering of applications with noise (Ester et al. 1996).

  • FOSC: Framework for optimal selection of clusters for unsupervised and semisupervised clustering of hierarchical cluster trees (Campello et al. 2013).

  • HDBSCAN: Hierarchical DBSCAN with simplified hierarchy extraction (Campello et al. 2015).

  • Jarvis-Patrick Clustering: Clustering using a similarity measure based on shared near neighbors (Jarvis and Patrick 1973).

  • OPTICS/OPTICSXi: Ordering points to identify the clustering structure and cluster extraction methods

  • SNN Clustering: Shared nearest neighbor clustering (Ertöz et al. 2003).

    (Ankerst et al. 1999).

Outlier Detection

  • LOF: Local outlier factor algorithm (Breunig et al. 2000).
  • GLOSH: Global-Local Outlier Score from Hierarchies algorithm (Campello et al. 2015).

Cluster Evaluation

  • DBCV: Density-based clustering validation (Moulavi et al. 2014).

Fast Nearest-Neighbor Search (using kd-trees)

  • kNN search
  • Fixed-radius NN search

The implementations use the kd-tree data structure (from library ANN) for faster k-nearest neighbor search, and are for Euclidean distance typically faster than the native R implementations (e.g., dbscan in package fpc), or the implementations in WEKA, ELKI and Python’s scikit-learn.

The following R packages use dbscan: AnimalSequences, autoFlagR, bioregion, clayringsmiletus, CLONETv2, clusterWebApp, cordillera, CPC, crosshap, cyclicwave, daltoolbox, DataSimilarity, diceR, discoCVI, dobin, doc2vec, dPCP, DrData, EHRtemporalVariability, emcAdr, eventstream, evprof, fastml, FCPS, fdacluster, flowcluster, flownet, FuelDeep3D, funtimes, HaploVar, immunaut, karyotapR, ksharp, LLMing, LOMAR, maotai, MapperAlgo, mditools, metaCluster, metasnf, mlr3cluster, neuroim2, oclust, omicsTools, openSkies, opticskxi, OTclust, outlierensembles, outlierMBC, pagoda2, parameters, performance, pguIMP, phynotype, PiC, quickOutlier, rarefun, rcrisp, Rhobots, riemannianStats, riskutility, rMultiNet, rtemis, SampleCore, seriation, sfdep, sfnetworks, sharp, smotefamily, snap, spCF, spdep, specmine, spNetwork, squat, ssel, ssMRCD, STATassist, stdbscan, stream, SuperCell, synr, tbnb, TextAnalysisR, tidyclust, tidylearn, tidySEM, tlsR, VBphenoR, VIProDesign, weird

To cite package ‘dbscan’ in publications use:

Hahsler M, Piekenbrock M, Doran D (2019). “dbscan: Fast Density-Based Clustering with R.” Journal of Statistical Software, 91(1), 1-30. .

@Article{,
  title = {dbscan: Fast Density-Based Clustering with {R}},
  author = {Michael Hahsler and Matthew Piekenbrock and Derek Doran},
  journal = {Journal of Statistical Software},
  year = {2019},
  volume = {91},
  number = {1},
  pages = {1--30},
  doi = {10.18637/jss.v091.i01},
}

Installation

Stable CRAN version: Install from within R with

r
install.packages("dbscan")

Current development version: Install from r-universe.

r
install.packages("dbscan",
    repos = c("https://mhahsler.r-universe.dev",
              "https://cloud.r-project.org/"))

Usage

Load the package and use the numeric variables in the iris dataset

r
library("dbscan")

data("iris")
x % dbscan(eps = .42, minPts = 5)

Get cluster statistics as a tibble

r
tidy(db)
## # A tibble: 4 × 3
##   cluster  size noise
##       
## 1 0          29 TRUE 
## 2 1          48 FALSE
## 3 2          37 FALSE
## 4 3          36 FALSE

Visualize the clustering with ggplot2 (use an x for noise points)

r
augment(db, x) %>% 
  ggplot(aes(x = Petal.Length, y = Petal.Width)) +
    geom_point(aes(color = .cluster, shape = noise)) +
    scale_shape_manual(values=c(19, 4))

Using dbscan from Python

R, the R package dbscan, and the Python package rpy2 need to be installed.

…
## DBSCAN clustering for 150 objects.
## Parameters: eps = 0.5, minPts = 5
## Using euclidean distances and borderpoints = TRUE
## The clustering contains 2 cluster(s) and 17 noise points.
## 
##  0  1  2 
## 17 49 84 
## 
## Available fields: cluster, eps, minPts, dist, borderPoints
python
# get the cluster assignment vector
labels = np.array(db.rx('cluster'))
labels
## array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
##         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1,
##         1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 0, 2, 2, 2, 2, 2,
##         2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
##         2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 0, 0, 2, 0, 0,
##         2, 2, 2, 2, 2, 2, 2, 0, 0, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0,
##         2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]],
##       dtype=int32)

License

The dbscan package is licensed under the GNU General Public License (GPL) Version 3. The OPTICSXi R implementation was directly ported from the ELKI framework’s Java implementation (GNU AGPLv3), with permission by the original author, Erich Schubert.

Changes

  • List of changes from NEWS.md

References

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++clusteringcrandbscandensity-based-clustering

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言