pub struct Dbscan<D: DistanceMetric = Euclidean> { /* private fields */ }Expand description
DBSCAN clustering algorithm, generic over a distance metric.
The default metric is Euclidean (L2), matching the original behavior
where epsilon is compared against Euclidean distance.
use clump::{Dbscan, Clustering, NOISE};
let data = vec![
vec![0.0f32, 0.0], vec![0.1, 0.0], vec![0.0, 0.1], // cluster
vec![100.0, 100.0], // outlier
];
let labels = Dbscan::new(0.5, 2).fit_predict(&data).unwrap();
assert_eq!(labels[0], labels[1]); // same cluster
assert_eq!(labels[3], NOISE); // outlier is noiseImplementations§
Source§impl Dbscan<Euclidean>
impl Dbscan<Euclidean>
Sourcepub fn new(epsilon: f32, min_pts: usize) -> Self
pub fn new(epsilon: f32, min_pts: usize) -> Self
Create a new DBSCAN clusterer with the default Euclidean distance.
§Arguments
epsilon- Maximum distance between two points to be neighbors.min_pts- Minimum number of points to form a dense region.
§Typical Values
epsilon: Often determined by k-distance plot (k = min_pts - 1).min_pts: 2 * dimension is a common heuristic. Minimum is 3.
Source§impl<D: DistanceMetric> Dbscan<D>
impl<D: DistanceMetric> Dbscan<D>
Sourcepub fn with_metric(epsilon: f32, min_pts: usize, metric: D) -> Self
pub fn with_metric(epsilon: f32, min_pts: usize, metric: D) -> Self
Create a new DBSCAN clusterer with a custom distance metric.
Sourcepub fn with_epsilon(self, epsilon: f32) -> Self
pub fn with_epsilon(self, epsilon: f32) -> Self
Set epsilon (neighborhood radius).
Sourcepub fn with_min_pts(self, min_pts: usize) -> Self
pub fn with_min_pts(self, min_pts: usize) -> Self
Set minimum points for core classification.
Trait Implementations§
Source§impl<D: DistanceMetric> Clustering for Dbscan<D>
impl<D: DistanceMetric> Clustering for Dbscan<D>
Source§fn n_clusters(&self) -> usize
fn n_clusters(&self) -> usize
DBSCAN discovers clusters dynamically, so this returns 0.
To get the actual number of clusters, examine the labels after fit_predict.
Source§impl<D: DistanceMetric> DbscanExt for Dbscan<D>
impl<D: DistanceMetric> DbscanExt for Dbscan<D>
Auto Trait Implementations§
impl<D> Freeze for Dbscan<D>where
D: Freeze,
impl<D> RefUnwindSafe for Dbscan<D>where
D: RefUnwindSafe,
impl<D> Send for Dbscan<D>
impl<D> Sync for Dbscan<D>
impl<D> Unpin for Dbscan<D>where
D: Unpin,
impl<D> UnsafeUnpin for Dbscan<D>where
D: UnsafeUnpin,
impl<D> UnwindSafe for Dbscan<D>where
D: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more