pub struct VarianceThreshold {
pub threshold: f64,
}Expand description
Parameters for VarianceThreshold feature selector (unfitted state).
Removes all features whose variance does not meet a minimum threshold.
By default (threshold = 0.0), it removes features that have zero variance,
i.e., features that are constant across all samples.
This is a simple baseline approach to feature selection: a feature with higher variance is more likely to be informative (though this is not guaranteed).
§Example
use anofox_ml_preprocessing::VarianceThreshold;
use anofox_ml_core::{FitUnsupervised, Transform};
use ndarray::array;
let x = array![
[0.0, 2.0, 0.0],
[0.0, 4.0, 0.0],
[0.0, 6.0, 0.0],
];
// Remove zero-variance features (columns 0 and 2 are constant)
let selector = VarianceThreshold::new(0.0);
let fitted = FitUnsupervised::<f64>::fit(&selector, &x).unwrap();
let x_selected = fitted.transform(&x).unwrap();
assert_eq!(x_selected.ncols(), 1); // only the varying column survivesFields§
§threshold: f64Minimum variance required for a feature to be kept. Features with variance <= threshold are removed.
Implementations§
Source§impl VarianceThreshold
impl VarianceThreshold
Sourcepub fn new(threshold: f64) -> VarianceThreshold
pub fn new(threshold: f64) -> VarianceThreshold
Create a new VarianceThreshold with the given threshold.
A threshold of 0.0 removes only constant (zero-variance) features.
Sourcepub fn with_threshold(self, threshold: f64) -> VarianceThreshold
pub fn with_threshold(self, threshold: f64) -> VarianceThreshold
Set the variance threshold.
Trait Implementations§
Source§impl Clone for VarianceThreshold
impl Clone for VarianceThreshold
Source§fn clone(&self) -> VarianceThreshold
fn clone(&self) -> VarianceThreshold
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 VarianceThreshold
impl Debug for VarianceThreshold
Source§impl Default for VarianceThreshold
impl Default for VarianceThreshold
Source§fn default() -> VarianceThreshold
fn default() -> VarianceThreshold
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for VarianceThreshold
impl<'de> Deserialize<'de> for VarianceThreshold
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<VarianceThreshold, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<VarianceThreshold, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<F> FitUnsupervised<F> for VarianceThresholdwhere
F: Float,
impl<F> FitUnsupervised<F> for VarianceThresholdwhere
F: Float,
type Fitted = FittedVarianceThreshold<F>
fn fit( &self, x: &ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ) -> Result<<VarianceThreshold as FitUnsupervised<F>>::Fitted, RustMlError>
Source§impl Serialize for VarianceThreshold
impl Serialize for VarianceThreshold
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for VarianceThreshold
impl RefUnwindSafe for VarianceThreshold
impl Send for VarianceThreshold
impl Sync for VarianceThreshold
impl Unpin for VarianceThreshold
impl UnsafeUnpin for VarianceThreshold
impl UnwindSafe for VarianceThreshold
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> SendAlias 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.