Categories &

Functions List

Function Reference: dbscan

statistics: idx = dbscan (X, epsilon, minpts)
statistics: idx = dbscan (D, epsilon, minpts, 'Distance', 'precomputed')
statistics: idx = dbscan (…, name, value)
statistics: [idx, corepts] = dbscan (…)

Density-Based Spatial Clustering of Applications with Noise (DBSCAN).

idx = dbscan (X, epsilon, minpts) partitions the observations in the N×P numeric matrix X into clusters using the DBSCAN algorithm with neighborhood radius epsilon and minimum number of neighbors minpts. Rows of X correspond to observations and columns correspond to features or variables. epsilon must be a nonnegative scalar and minpts a positive integer scalar. idx is an N×1 vector of cluster indices, numbered 1 to the number of clusters found; observations flagged as noise are assigned the value -1.

A point is a core point when at least minpts observations (including the point itself) lie within distance epsilon of it. Clusters grow from core points to every observation that is density-reachable from them; a non-core observation that lies within epsilon of a core point becomes a border point and joins that point’s cluster, while an observation that is neither core nor within reach of a core point is labelled noise. A border point that is reachable from more than one cluster is assigned to the first cluster that reaches it, following the order of the observations in X.

idx = dbscan (D, epsilon, minpts, 'Distance', 'precomputed') treats the N×N matrix D as a precomputed matrix of pairwise distances between observations, such as the output of pdist2; D(i,j) is the distance between observations i and j.

[idx, corepts] = dbscan (…) also returns an N×1 logical vector corepts that is true for each observation that is a core point.

Additional parameters can be specified by Name-Value pair arguments.

NameValue
'Distance'is the distance metric used to find neighbors, specified as one of the metrics accepted by rangesearch ('euclidean' by default, and also 'seuclidean', 'cityblock', 'chebychev', 'minkowski', 'mahalanobis', 'cosine', 'correlation', 'spearman', 'hamming', 'jaccard', or a custom distance function handle), or the string 'precomputed' to interpret the first input as a matrix of pairwise distances.
'P'is the Minkowski distance exponent, a positive scalar. This argument is only valid when the selected distance metric is 'minkowski'. By default it is 2.
'Scale'is the scale parameter for the standardized Euclidean distance, a nonnegative numeric vector of length equal to the number of columns in X. This argument is only valid when the selected distance metric is 'seuclidean'.
'Cov'is the covariance matrix for the mahalanobis distance, a positive definite matrix matching the number of columns in X. This argument is only valid when the selected distance metric is 'mahalanobis'.

Source Code: dbscan

See also: kmeans, rangesearch, pdist2, knnsearch

Source Code: dbscan

Cluster a set of points with two dense blobs and scattered noise.

 X = [randn(30,2)*0.3 + 2; randn(30,2)*0.3 - 2; 5*(rand(6,2)-0.5)];
 idx = dbscan (X, 0.6, 4);
 gscatter (X(:,1), X(:,2), idx);
 title ("dbscan: clusters (>=0) and noise (-1)");
plotted figure