#[non_exhaustive]pub enum ClassWeight {
Uniform,
Balanced,
Custom(HashMap<usize, f64>),
}Expand description
Strategy for weighting classes during training.
Used by classifiers to handle imbalanced datasets. When set to Balanced,
minority classes receive higher weight, making the model pay more attention
to underrepresented classes.
§Example
use scry_learn::weights::ClassWeight;
use scry_learn::tree::DecisionTreeClassifier;
let dt = DecisionTreeClassifier::new()
.class_weight(ClassWeight::Balanced);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Uniform
All classes weighted equally (weight = 1.0). This is the default.
Balanced
Automatically adjust weights inversely proportional to class frequencies.
Uses the sklearn formula: weight_c = n_samples / (n_classes × n_c).
Custom(HashMap<usize, f64>)
User-specified per-class weights (class label → weight).
Trait Implementations§
Source§impl Clone for ClassWeight
impl Clone for ClassWeight
Source§fn clone(&self) -> ClassWeight
fn clone(&self) -> ClassWeight
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 Debug for ClassWeight
impl Debug for ClassWeight
Source§impl Default for ClassWeight
impl Default for ClassWeight
Source§fn default() -> ClassWeight
fn default() -> ClassWeight
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ClassWeight
impl RefUnwindSafe for ClassWeight
impl Send for ClassWeight
impl Sync for ClassWeight
impl Unpin for ClassWeight
impl UnsafeUnpin for ClassWeight
impl UnwindSafe for ClassWeight
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> 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