#[non_exhaustive]pub enum KMeansAlgorithm {
Lloyd,
Hamerly,
}Expand description
Specifies the algorithm used for the KMeans assignment step.
Both variants minimise the same objective and, given identical initial centroids,
converge to the same result. They only differ in how the assignment step is computed.
Select a variant via KMeansParams::algorithm.
This setting only applies to batch fit. The incremental Mini-Batch K-means path
(fit_with) always uses Lloyd’s update, and configuring Hamerly alongside
fit_with is rejected with
KMeansParamsError::IncrementalHamerly.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Lloyd
Standard Lloyd’s algorithm (also known as the “naive” algorithm).
On every iteration, computes the distance from each observation to every centroid
to determine the closest one. Simple and predictable; work per iteration is
O(n_observations * n_clusters * n_features).
Default variant. Works with any Distance.
Hamerly
Hamerly’s accelerated algorithm.
Uses the triangle inequality together with per-observation upper/lower distance
bounds to skip most distance computations once the algorithm has stabilised.
Produces the same result as Lloyd’s algorithm given the same initial centroids,
and is typically substantially faster for well-separated clusters with a moderate
number of centroids. For heavily overlapping clusters or very large n_clusters
the bookkeeping overhead can make Lloyd a better choice.
Because the bounds rely on the triangle inequality, the supplied distance
function must be a true metric. L2Dist, L1Dist and LInfDist satisfy this.
Only supported in batch fit; not available for Mini-Batch fit_with.
Reference: https://cs.baylor.edu/~hamerly/papers/sdm_2010.pdf
Trait Implementations§
Source§impl Clone for KMeansAlgorithm
impl Clone for KMeansAlgorithm
Source§fn clone(&self) -> KMeansAlgorithm
fn clone(&self) -> KMeansAlgorithm
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KMeansAlgorithm
impl Debug for KMeansAlgorithm
Source§impl PartialEq for KMeansAlgorithm
impl PartialEq for KMeansAlgorithm
impl Copy for KMeansAlgorithm
impl Eq for KMeansAlgorithm
impl StructuralPartialEq for KMeansAlgorithm
Auto Trait Implementations§
impl Freeze for KMeansAlgorithm
impl RefUnwindSafe for KMeansAlgorithm
impl Send for KMeansAlgorithm
impl Sync for KMeansAlgorithm
impl Unpin for KMeansAlgorithm
impl UnsafeUnpin for KMeansAlgorithm
impl UnwindSafe for KMeansAlgorithm
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<B> Stagewise for B
impl<B> Stagewise for B
§fn chain_shrunk<C, F>(
self,
corrector: Shrunk<C, F>,
) -> ResidualChainParams<B, C, F>where
F: Float,
fn chain_shrunk<C, F>(
self,
corrector: Shrunk<C, F>,
) -> ResidualChainParams<B, C, F>where
F: Float,
self (as the base model) with a [Shrunk]-wrapped corrector,
which will be trained on the residuals left by self. Further stages can
be appended by calling .chain(...) or .chain_shrunk(...) on the
returned [ResidualChainParams]. Read more§fn chain<C, F, E>(self, corrector: C) -> ResidualChainParams<B, C, F>
fn chain<C, F, E>(self, corrector: C) -> ResidualChainParams<B, C, F>
self (as the base model) with corrector, which will be
trained on the residuals left by self. The corrector is used without
shrinkage (equivalent to shrink_by(1.0)). Further stages can be
appended by calling .chain(...) or .chain_shrunk(...) on the
returned [ResidualChainParams]. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.