pub struct SelectFromModel<F> { /* private fields */ }Expand description
A feature selector driven by external feature-importance weights.
The importance vector is typically obtained from a fitted model (e.g. a
decision-tree model’s feature_importances_ field). Features whose
importance is strictly greater than or equal to the threshold are kept.
The default threshold is the mean importance of all features.
§Examples
use ferrolearn_preprocess::feature_selection::SelectFromModel;
use ferrolearn_core::traits::Transform;
use ndarray::array;
let importances = array![0.1, 0.5, 0.4];
let sel = SelectFromModel::<f64>::new_from_importances(&importances, None).unwrap();
let x = array![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
let out = sel.transform(&x).unwrap();
// Mean importance = (0.1+0.5+0.4)/3 ≈ 0.333; columns 1 and 2 are kept
assert_eq!(out.ncols(), 2);Implementations§
Source§impl<F: Float + Send + Sync + 'static> SelectFromModel<F>
impl<F: Float + Send + Sync + 'static> SelectFromModel<F>
Sourcepub fn new_from_importances(
importances: &Array1<F>,
threshold: Option<F>,
) -> Result<Self, FerroError>
pub fn new_from_importances( importances: &Array1<F>, threshold: Option<F>, ) -> Result<Self, FerroError>
Create a SelectFromModel from a pre-computed importance vector.
§Parameters
importances— one importance weight per feature.threshold— optional explicit threshold; ifNonethe mean importance is used.
§Errors
Returns FerroError::InvalidParameter if importances is empty.
Sourcepub fn importances(&self) -> &Array1<F>
pub fn importances(&self) -> &Array1<F>
Return the importance vector supplied at construction time.
Sourcepub fn selected_indices(&self) -> &[usize]
pub fn selected_indices(&self) -> &[usize]
Return the indices of the selected columns.
Trait Implementations§
Source§impl<F: Clone> Clone for SelectFromModel<F>
impl<F: Clone> Clone for SelectFromModel<F>
Source§fn clone(&self) -> SelectFromModel<F>
fn clone(&self) -> SelectFromModel<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for SelectFromModel<F>
impl<F: Debug> Debug for SelectFromModel<F>
Source§impl<F: Float + Send + Sync + 'static> FittedPipelineTransformer<F> for SelectFromModel<F>
impl<F: Float + Send + Sync + 'static> FittedPipelineTransformer<F> for SelectFromModel<F>
Source§fn transform_pipeline(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn transform_pipeline(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Source§impl<F: Float + Send + Sync + 'static> PipelineTransformer<F> for SelectFromModel<F>
impl<F: Float + Send + Sync + 'static> PipelineTransformer<F> for SelectFromModel<F>
Source§fn fit_pipeline(
&self,
_x: &Array2<F>,
_y: &Array1<F>,
) -> Result<Box<dyn FittedPipelineTransformer<F>>, FerroError>
fn fit_pipeline( &self, _x: &Array2<F>, _y: &Array1<F>, ) -> Result<Box<dyn FittedPipelineTransformer<F>>, FerroError>
Clone the selector and box it as a fitted pipeline transformer.
§Errors
This implementation never fails.
Source§impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for SelectFromModel<F>
impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for SelectFromModel<F>
Source§fn transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Return a matrix containing only the columns whose importance exceeds the threshold.
§Errors
Returns FerroError::ShapeMismatch if the number of columns differs
from the length of the importance vector supplied at construction.
Source§type Error = FerroError
type Error = FerroError
transform.Auto Trait Implementations§
impl<F> Freeze for SelectFromModel<F>where
F: Freeze,
impl<F> RefUnwindSafe for SelectFromModel<F>where
F: RefUnwindSafe,
impl<F> Send for SelectFromModel<F>where
F: Send,
impl<F> Sync for SelectFromModel<F>where
F: Sync,
impl<F> Unpin for SelectFromModel<F>where
F: Unpin,
impl<F> UnsafeUnpin for SelectFromModel<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for SelectFromModel<F>where
F: UnwindSafe + RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable 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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.