pub struct Kmeans<D: DistanceMetric = SquaredEuclidean> { /* private fields */ }Expand description
K-means clustering algorithm, generic over a distance metric.
The default metric is clump::SquaredEuclidean, preserving backward
compatibility: Kmeans::new(k) works exactly as before.
To use a different metric, construct via Kmeans::with_metric:
use sheaf::cluster::{Kmeans, CosineDistance};
let km = Kmeans::with_metric(8, CosineDistance).with_seed(42);Implementations§
Source§impl<D: DistanceMetric> Kmeans<D>
impl<D: DistanceMetric> Kmeans<D>
Sourcepub fn with_metric(k: usize, metric: D) -> Self
pub fn with_metric(k: usize, metric: D) -> Self
Create a new K-means clusterer with a custom distance metric.
Sourcepub fn with_max_iter(self, max_iter: usize) -> Self
pub fn with_max_iter(self, max_iter: usize) -> Self
Set maximum iterations.
Sourcepub fn with_seeding_alpha(self, alpha: f32) -> Self
pub fn with_seeding_alpha(self, alpha: f32) -> Self
Set seeding alpha (exponent for k-means++ probability weighting).
Standard k-means++ uses alpha=2.0 (D-squared weighting). Research (Bamas et al. 2023) suggests alpha > 2 (e.g. 4.0) can yield better final clustering cost.
Trait Implementations§
Source§impl<D: DistanceMetric> Clustering for Kmeans<D>
impl<D: DistanceMetric> Clustering for Kmeans<D>
Auto Trait Implementations§
impl<D> Freeze for Kmeans<D>where
D: Freeze,
impl<D> RefUnwindSafe for Kmeans<D>where
D: RefUnwindSafe,
impl<D> Send for Kmeans<D>
impl<D> Sync for Kmeans<D>
impl<D> Unpin for Kmeans<D>where
D: Unpin,
impl<D> UnsafeUnpin for Kmeans<D>where
D: UnsafeUnpin,
impl<D> UnwindSafe for Kmeans<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> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
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