v2026.6.1
All Bundles
Bundle Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.

DBSCAN

Density-based spatial clustering (DBSCAN). Groups points that are densely packed (at least min_points neighbors within eps, Euclidean) and labels sparse points as noise (-1). Unlike KMeans the cluster count is discovered, clusters may be any shape, and the result is deterministic for a given input order.

Example

scanner := DBSCAN->New(1.0, 3);
scanner->Fit(X);
labels := scanner->GetLabels();   # cluster id per row; -1 = noise

Operations

Fit #

Clusters the data. Region growing visits rows in order, so results are deterministic for a given input.

method : public : Fit(X:Float[,]) ~ Bool

Parameters

NameTypeDescription
XFloatdata matrix (rows=samples, cols=features)

Return

TypeDescription
Booltrue if clustering succeeded

GetLabels #

Gets the per-row cluster labels (-1 = noise).

method : public : GetLabels() ~ Int[]

Return

TypeDescription
Intlabel array, or Nil if not fitted

GetNumClusters #

Gets the number of clusters discovered.

method : public : GetNumClusters() ~ Int

Return

TypeDescription
Intcluster count

IsFitted #

Whether the clustering has been run.

method : public : IsFitted() ~ Bool

Return

TypeDescription
Booltrue if fitted

New # constructor

Constructor

New(eps:Float, min_points:Int)

Parameters

NameTypeDescription
epsFloatneighborhood radius (Euclidean)
min_pointsIntminimum neighbors (inclusive of the point itself) for a core point