pub struct SelectFromModel {
pub threshold: Option<f64>,
pub max_features: Option<usize>,
}Expand description
Parameters for SelectFromModel feature selector (unfitted state).
Selects features based on a pre-computed importance vector (e.g., from a
fitted RandomForestClassifier’s
feature_importances()).
Features can be selected in two ways:
- Threshold: keep all features with importance >= threshold.
- Max features: keep the top
max_featuresfeatures by importance.
If both are specified, threshold is applied first and then the result is
capped to max_features.
Since this selector does not learn from raw data (it uses pre-computed
importances), it exposes a custom fit method instead of implementing the
standard FitUnsupervised trait.
§Example
use anofox_ml_preprocessing::SelectFromModel;
use anofox_ml_core::Transform;
use ndarray::array;
let importances = array![0.05, 0.40, 0.10, 0.45];
// Select features with importance >= 0.20
let selector = SelectFromModel::new().with_threshold(0.20);
let fitted = selector.fit(&importances).unwrap();
assert_eq!(fitted.selected_indices(), &[1, 3]);
let x = array![
[1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0],
];
let x_selected = fitted.transform(&x).unwrap();
assert_eq!(x_selected.ncols(), 2);Fields§
§threshold: Option<f64>Features with importance >= threshold are selected.
If None, no threshold filtering is applied.
max_features: Option<usize>Maximum number of features to select (top by importance).
If None, no cap is applied.
Implementations§
Source§impl SelectFromModel
impl SelectFromModel
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new SelectFromModel with no threshold and no feature cap.
At least one of threshold or max_features must be set before calling
fit.
Sourcepub fn with_threshold(self, threshold: f64) -> Self
pub fn with_threshold(self, threshold: f64) -> Self
Set the minimum importance threshold.
Sourcepub fn with_max_features(self, max_features: usize) -> Self
pub fn with_max_features(self, max_features: usize) -> Self
Set the maximum number of features to select.
Trait Implementations§
Source§impl Clone for SelectFromModel
impl Clone for SelectFromModel
Source§fn clone(&self) -> SelectFromModel
fn clone(&self) -> SelectFromModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SelectFromModel
impl Debug for SelectFromModel
Source§impl Default for SelectFromModel
impl Default for SelectFromModel
Source§impl<'de> Deserialize<'de> for SelectFromModel
impl<'de> Deserialize<'de> for SelectFromModel
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>,
Auto Trait Implementations§
impl Freeze for SelectFromModel
impl RefUnwindSafe for SelectFromModel
impl Send for SelectFromModel
impl Sync for SelectFromModel
impl Unpin for SelectFromModel
impl UnsafeUnpin for SelectFromModel
impl UnwindSafe for SelectFromModel
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
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>
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