density-凯发k8网页登录
density-based spatial clustering of applications with noise (dbscan)
since r2019a
syntax
description
partitions observations in the n-by-p data matrix
idx
= dbscan(x
,epsilon
,minpts
)x
into clusters using the dbscan algorithm (see algorithms).
dbscan
clusters the observations (or points) based on a threshold
for a neighborhood search radius epsilon
and a minimum number of
neighbors minpts
required to identify a core point. the function
returns an n-by-1 vector (idx
) containing cluster
indices of each observation.
returns a vector of cluster indices for the precomputed pairwise distances
idx
= dbscan(d
,epsilon
,minpts
,'distance'
,'precomputed')d
between observations. d
can be the output of
or , or a more general dissimilarity vector or matrix conforming to the
output format of pdist
or pdist2
,
respectively.
examples
input arguments
output arguments
more about
tips
for improved speed when iterating over many values of
epsilon
, consider passing ind
as the input todbscan
. this approach prevents the function from having to compute the distances at every point of the iteration.if you use to precompute
d
, do not specify the or name-value pair arguments ofpdist2
to select or sort columns ofd
. selecting fewer than n distances results in an error, becausedbscan
expectsd
to be a square matrix. sorting the distances in each column ofd
leads to a loss in the interpretation ofd
and can give meaningless results when used in thedbscan
function.for efficient memory usage, consider passing in
d
as a logical matrix rather than a numeric matrix todbscan
whend
is large. by default, matlab® stores each value in a numeric matrix using 8 bytes (64 bits), and each value in a logical matrix using 1 byte (8 bits).to select a value for
minpts
, consider a value greater than or equal to the number of dimensions of the input data plus one [1]. for example, for an n-by-p matrixx
, set'minpts'
equal to p 1 or greater.one possible strategy for selecting a value for
epsilon
is to generate a k-distance graph forx
. for each point inx
, find the distance to the kth nearest point, and plot sorted points against this distance. generally, the graph contains a knee. the distance that corresponds to the knee is typically a good choice forepsilon
, because it is the region where points start tailing off into outlier (noise) territory [1].
algorithms
dbscan is a density-based clustering algorithm that is designed to discover clusters and noise in data. the algorithm identifies three kinds of points: core points, border points, and noise points [1]. for specified values of
epsilon
andminpts
, thedbscan
function implements the algorithm as follows:from the input data set
x
, select the first unlabeled observation x1 as the current point, and initialize the first cluster label c to 1.find the set of points within the epsilon neighborhood
epsilon
of the current point. these points are the neighbors.if the number of neighbors is less than
minpts
, then label the current point as a noise point (or an outlier). go to step 4.note
dbscan
can reassign noise points to clusters if the noise points later satisfy the constraints set byepsilon
andminpts
from some other point inx
. this process of reassigning points happens for border points of a cluster.otherwise, label the current point as a core point belonging to cluster c.
iterate over each neighbor (new current point) and repeat step 2 until no new neighbors are found that can be labeled as belonging to the current cluster c.
select the next unlabeled point in
x
as the current point, and increase the cluster count by 1.repeat steps 2–4 until all points in
x
are labeled.
if two clusters have varying densities and are close to each other, that is, the distance between two border points (one from each cluster) is less than
epsilon
, thendbscan
can merge the two clusters into one.every valid cluster might not contain at least
minpts
observations. for example,dbscan
can identify a border point belonging to two clusters that are close to each other. in such a situation, the algorithm assigns the border point to the first discovered cluster. as a result, the second cluster is still a valid cluster, but it can have fewer thanminpts
observations.
references
[1] ester, m., h.-p. kriegel, j. sander, and x. xiaowei. “a density-based algorithm for discovering clusters in large spatial databases with noise.” in proceedings of the second international conference on knowledge discovery in databases and data mining, 226-231. portland, or: aaai press, 1996.
version history
introduced in r2019a