1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use thiserror::Error;
#[derive(Error, Debug)]
pub enum KMeansParamsError {
#[error("n_clusters cannot be 0")]
NClusters,
#[error("n_runs cannot be 0")]
NRuns,
#[error("tolerance must be greater than 0")]
Tolerance,
#[error("max_n_iterations cannot be 0")]
MaxIterations,
}
#[derive(Error, Debug)]
pub enum KMeansError {
#[error("Invalid hyperparameter: {0}")]
InvalidParams(#[from] KMeansParamsError),
#[error("Fitting failed: No inertia improvement (-inf)")]
InertiaError,
#[error("Fitting failed: Did not converge. Try different init parameters or check for degenerate data.")]
NotConverged,
#[error(transparent)]
LinfaError(#[from] linfa::error::Error),
}
#[derive(Error, Debug)]
pub enum IncrKMeansError<M: std::fmt::Debug> {
#[error("Invalid hyperparameter: {0}")]
InvalidParams(#[from] KMeansParamsError),
#[error("Algorithm has not yet converged, Keep on running the algorithm.")]
NotConverged(M),
#[error(transparent)]
LinfaError(#[from] linfa::error::Error),
}