pub struct KMeansModel {
pub centroids: Array2<f64>,
pub n_clusters: usize,
pub n_iter: usize,
pub inertia: f64,
pub labels: Option<Array1<usize>>,
}Expand description
K-means clustering model that can be serialized
Fields§
§centroids: Array2<f64>Cluster centroids
n_clusters: usizeNumber of clusters
n_iter: usizeNumber of iterations performed
inertia: f64Sum of squared distances
labels: Option<Array1<usize>>Cluster labels for training data (optional)
Implementations§
Source§impl KMeansModel
impl KMeansModel
Sourcepub fn new(
centroids: Array2<f64>,
n_clusters: usize,
n_iter: usize,
inertia: f64,
labels: Option<Array1<usize>>,
) -> Self
pub fn new( centroids: Array2<f64>, n_clusters: usize, n_iter: usize, inertia: f64, labels: Option<Array1<usize>>, ) -> Self
Create a new K-means model
Sourcepub fn predict(&self, data: ArrayView2<'_, f64>) -> Result<Array1<usize>>
pub fn predict(&self, data: ArrayView2<'_, f64>) -> Result<Array1<usize>>
Predict cluster labels for new data
Sourcepub fn predict_single(&self, point: &[f64]) -> Result<usize>
pub fn predict_single(&self, point: &[f64]) -> Result<usize>
Get the closest cluster center for a single point
Trait Implementations§
Source§impl AdvancedExport for KMeansModel
Implementation of AdvancedExport for KMeansModel
impl AdvancedExport for KMeansModel
Implementation of AdvancedExport for KMeansModel
Source§fn export_with_metadata(
&self,
format: ExportFormat,
metadata: Option<ModelMetadata>,
) -> Result<Vec<u8>>
fn export_with_metadata( &self, format: ExportFormat, metadata: Option<ModelMetadata>, ) -> Result<Vec<u8>>
Export model to specified format with metadata
Source§fn export_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
fn export_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
Export to file with automatic format detection
Source§fn export_summary(&self) -> Result<String>
fn export_summary(&self) -> Result<String>
Export model summary for quick inspection
Source§fn export_compatible(&self, target_library: &str) -> Result<Value>
fn export_compatible(&self, target_library: &str) -> Result<Value>
Export model in a format compatible with other libraries
Source§fn validate_for_export(&self) -> Result<()>
fn validate_for_export(&self) -> Result<()>
Validate model before export
Source§impl Clone for KMeansModel
impl Clone for KMeansModel
Source§fn clone(&self) -> KMeansModel
fn clone(&self) -> KMeansModel
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl ClusteringModel for KMeansModel
impl ClusteringModel for KMeansModel
Source§impl Debug for KMeansModel
impl Debug for KMeansModel
Source§impl<'de> Deserialize<'de> for KMeansModel
impl<'de> Deserialize<'de> for KMeansModel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl SerializableModel for KMeansModel
impl SerializableModel for KMeansModel
Source§fn save_to_file_compressed<P: AsRef<Path>>(&self, path: P) -> Result<()>
fn save_to_file_compressed<P: AsRef<Path>>(&self, path: P) -> Result<()>
Save the model to a file with compression
Source§fn load_from_file_compressed<P: AsRef<Path>>(path: P) -> Result<Self>
fn load_from_file_compressed<P: AsRef<Path>>(path: P) -> Result<Self>
Load the model from a compressed file
Source§fn load_from_reader<R: Read>(reader: R) -> Result<Self>
fn load_from_reader<R: Read>(reader: R) -> Result<Self>
Load the model from a reader
Auto Trait Implementations§
impl Freeze for KMeansModel
impl RefUnwindSafe for KMeansModel
impl Send for KMeansModel
impl Sync for KMeansModel
impl Unpin for KMeansModel
impl UnsafeUnpin for KMeansModel
impl UnwindSafe for KMeansModel
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> SerializableAny for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.