dbscan
Builtin index · Statistics & ML
result = dbscan(X, eps, min_samples)
Input: X, eps, min_samples · Output: result
What it is
Density-based clustering on an N-row, D-column data matrix X: a number eps (the neighbourhood radius, in X's own units) and an integer min_samples (the minimum neighbourhood size to count as a dense core point).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = dbscan(X, eps, min_samples) | X matrix or numbernot documented yeteps matrix or numbernot documented yetmin_samples matrix or numbernot documented yet | result vector | Returns a length-N vector of integer cluster labels; points that fall in no dense cluster get label -1. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
G = vstack(randn(40, 2, seed = 31) + 4,
randn(40, 2, seed = 32) - 4,
randn(40, 2, seed = 33))
d = dbscan(G, 1.5, 4)
print("dbscan labels: {distinct(d)}")
proj = pca(G, 2) # the (n, 2) projected coordinates
comps = pca_components(G, 2) # the (2, 2) loading matrix
ev = pca_explained_variance(G, 2)
print("pca projected shape: {rows(proj)} x {cols(proj)}")
print("pca components:\n{round(comps, 3)}")
print("explained variance: {round(ev, 3)}")
small = vstack(randn(6, 2, seed = 41) + 3, randn(6, 2, seed = 42) - 3)
low = tsne(small, n_components = 2, perplexity = 3, seed = 1, max_iter = 100)
print("tsne output rows: {rows(low)}")
dbscan labels: (0, 1, 2) pca projected shape: 120 x 2 pca components: [0.694, 0.72; 0.72, -0.694] explained variance: [0.969, 0.031] tsne output rows: 12
from statistics-ml
How it works
dbscan(X, eps, min_samples) — density-based clustering (Ester et al. 1996). No _model suffix: like kmeans/ kmeans_centers, DBSCAN is fundamentally transductive (a point's cluster depends on the *whole* dataset's local density around it, not a reusable decision boundary learned once and replayed on new data), so there's no meaningful .predict(Xnew) to build a model handle around — this returns just the training-set label vector, the same "flat function, not a model" precedent kmeans itself sets. Labels are cluster ids 0..num_clusters for core/border points; points no cluster ever reaches get the conventional noise label -1. eps is a plain Euclidean distance in X's own units (no automatic scaling); min_samples includes the point itself (scikit-learn's convention, not the "excluding self" variant some textbooks use).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.