#[non_exhaustive]pub struct Dbscan { /* private fields */ }Expand description
DBSCAN (Density-Based Spatial Clustering of Applications with Noise).
Points are classified as core, border, or noise based on neighborhood density. Supports configurable distance metrics and KD-tree acceleration.
§Example
use scry_learn::cluster::Dbscan;
use scry_learn::dataset::Dataset;
let data = Dataset::new(
vec![vec![0.0, 0.0, 10.0, 10.0], vec![0.0, 0.0, 10.0, 10.0]],
vec![0.0; 4],
vec!["x".into(), "y".into()],
"label",
);
let mut db = Dbscan::new(5.0, 2);
db.fit(&data).unwrap();
assert_eq!(db.n_clusters(), 2);Implementations§
Source§impl Dbscan
impl Dbscan
Sourcepub fn new(eps: f64, min_samples: usize) -> Self
pub fn new(eps: f64, min_samples: usize) -> Self
Create a new DBSCAN model.
§Arguments
eps— maximum distance for two points to be considered neighbors.min_samples— minimum number of neighbors for a point to be a core point.
Sourcepub fn metric(self, m: DistanceMetric) -> Self
pub fn metric(self, m: DistanceMetric) -> Self
Set the distance metric.
Default is DistanceMetric::Euclidean. KD-tree acceleration is only
used with Euclidean distance and ≤ 20 features; other metrics always
use brute-force.
Sourcepub fn fit(&mut self, data: &Dataset) -> Result<()>
pub fn fit(&mut self, data: &Dataset) -> Result<()>
Fit the model on a dataset.
Uses KD-tree for Euclidean distance with ≤ 20 features, brute-force otherwise.
Sourcepub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<i32>>
pub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<i32>>
Predict cluster labels for new points.
Each new point is assigned to the cluster of its nearest core point
if that core point is within eps. Otherwise the point is labeled noise (-1).
§Example
use scry_learn::cluster::Dbscan;
use scry_learn::dataset::Dataset;
let data = Dataset::new(
vec![vec![0.0, 0.0, 0.0, 10.0, 10.0, 10.0],
vec![0.0, 0.0, 0.0, 10.0, 10.0, 10.0]],
vec![0.0; 6],
vec!["x".into(), "y".into()],
"label",
);
let mut db = Dbscan::new(5.0, 2);
db.fit(&data).unwrap();
let preds = db.predict(&[vec![0.5, 0.5]]).unwrap();
assert!(preds[0] >= 0, "Should be assigned to a cluster");Sourcepub fn n_clusters(&self) -> usize
pub fn n_clusters(&self) -> usize
Number of clusters found (excluding noise).
Sourcepub fn n_core_points(&self) -> usize
pub fn n_core_points(&self) -> usize
Number of core points identified during fitting.
Auto Trait Implementations§
impl Freeze for Dbscan
impl RefUnwindSafe for Dbscan
impl Send for Dbscan
impl Sync for Dbscan
impl Unpin for Dbscan
impl UnsafeUnpin for Dbscan
impl UnwindSafe for Dbscan
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
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>
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>
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