pub struct RFE<F> { /* private fields */ }Expand description
Recursive Feature Elimination.
Starting from all features, repeatedly removes the step least-important
features until n_features_to_select features remain. The ranking is
determined by the importance vector supplied at construction.
§Examples
use ferrolearn_preprocess::rfe::RFE;
use ferrolearn_core::traits::Transform;
use ndarray::array;
// Feature importances: feature 0 is most important, feature 2 least
let importances = array![0.6, 0.3, 0.1];
let rfe = RFE::<f64>::new(&importances, 1, 1).unwrap();
assert_eq!(rfe.support(), &[true, false, false]);
assert_eq!(rfe.ranking(), &[1, 2, 3]);
let x = array![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
let out = rfe.transform(&x).unwrap();
assert_eq!(out.ncols(), 1);Implementations§
Source§impl<F: Float + Send + Sync + 'static> RFE<F>
impl<F: Float + Send + Sync + 'static> RFE<F>
Sourcepub fn new(
importances: &Array1<F>,
n_features_to_select: usize,
step: usize,
) -> Result<Self, FerroError>
pub fn new( importances: &Array1<F>, n_features_to_select: usize, step: usize, ) -> Result<Self, FerroError>
Create a new RFE from pre-computed feature importances.
§Parameters
importances— per-feature importance scores (higher = more important).n_features_to_select— number of features to keep.step— number of features to remove per iteration.
§Errors
FerroError::InvalidParameterifimportancesis empty,stepis zero, orn_features_to_selectexceeds the number of features.
Sourcepub fn ranking(&self) -> &[usize]
pub fn ranking(&self) -> &[usize]
Return the feature ranking (1 = best, higher = eliminated earlier).
Sourcepub fn selected_indices(&self) -> &[usize]
pub fn selected_indices(&self) -> &[usize]
Return the indices of the selected features.
Sourcepub fn n_features_selected(&self) -> usize
pub fn n_features_selected(&self) -> usize
Return the number of selected features.
Trait Implementations§
Source§impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for RFE<F>
impl<F: Float + Send + Sync + 'static> Transform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for RFE<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 selected features.
§Errors
Returns FerroError::ShapeMismatch if the number of columns differs
from the number of features used at construction.
Source§type Error = FerroError
type Error = FerroError
The error type returned by
transform.Auto Trait Implementations§
impl<F> Freeze for RFE<F>
impl<F> RefUnwindSafe for RFE<F>where
F: RefUnwindSafe,
impl<F> Send for RFE<F>where
F: Send,
impl<F> Sync for RFE<F>where
F: Sync,
impl<F> Unpin for RFE<F>where
F: Unpin,
impl<F> UnsafeUnpin for RFE<F>
impl<F> UnwindSafe for RFE<F>where
F: UnwindSafe,
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> 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
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.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§unsafe fn to_subset_unchecked(&self) -> SS
unsafe 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.