pub struct SelectKBest<F> { /* private fields */ }Expand description
An unfitted K-best feature selector.
Requires class labels (Array1<usize>) at fit time to compute per-feature
ANOVA F-scores. The top K features (by score) are retained.
§Examples
use ferrolearn_preprocess::feature_selection::{SelectKBest, ScoreFunc};
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::{array, Array1};
let sel = SelectKBest::<f64>::new(1, ScoreFunc::FClassif);
let x = array![[1.0, 10.0], [1.0, 20.0], [2.0, 10.0], [2.0, 20.0]];
let y: Array1<usize> = array![0, 0, 1, 1];
let fitted = sel.fit(&x, &y).unwrap();
let out = fitted.transform(&x).unwrap();
assert_eq!(out.ncols(), 1);Implementations§
Source§impl<F: Float + Send + Sync + 'static> SelectKBest<F>
impl<F: Float + Send + Sync + 'static> SelectKBest<F>
Sourcepub fn new(k: usize, score_func: ScoreFunc) -> Self
pub fn new(k: usize, score_func: ScoreFunc) -> Self
Create a new SelectKBest selector.
§Parameters
k— the number of features to retain.score_func— the scoring function; currently onlyScoreFunc::FClassifis available.
Sourcepub fn score_func(&self) -> ScoreFunc
pub fn score_func(&self) -> ScoreFunc
Return the score function.
Trait Implementations§
Source§impl<F: Clone> Clone for SelectKBest<F>
impl<F: Clone> Clone for SelectKBest<F>
Source§fn clone(&self) -> SelectKBest<F>
fn clone(&self) -> SelectKBest<F>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<F: Debug> Debug for SelectKBest<F>
impl<F: Debug> Debug for SelectKBest<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>> for SelectKBest<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>> for SelectKBest<F>
Source§fn fit(
&self,
x: &Array2<F>,
y: &Array1<usize>,
) -> Result<FittedSelectKBest<F>, FerroError>
fn fit( &self, x: &Array2<F>, y: &Array1<usize>, ) -> Result<FittedSelectKBest<F>, FerroError>
Fit by computing per-feature ANOVA F-scores against the class labels.
§Errors
FerroError::InsufficientSamplesif the input has zero rows.FerroError::InvalidParameterifkexceeds the number of features.FerroError::ShapeMismatchifxandyhave different numbers of rows.
Source§type Fitted = FittedSelectKBest<F>
type Fitted = FittedSelectKBest<F>
The fitted model type returned by
fit.Source§type Error = FerroError
type Error = FerroError
The error type returned by
fit.Source§impl<F: Float + Send + Sync + 'static> PipelineTransformer<F> for SelectKBest<F>
impl<F: Float + Send + Sync + 'static> PipelineTransformer<F> for SelectKBest<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>
Auto Trait Implementations§
impl<F> Freeze for SelectKBest<F>
impl<F> RefUnwindSafe for SelectKBest<F>where
F: RefUnwindSafe,
impl<F> Send for SelectKBest<F>where
F: Send,
impl<F> Sync for SelectKBest<F>where
F: Sync,
impl<F> Unpin for SelectKBest<F>where
F: Unpin,
impl<F> UnsafeUnpin for SelectKBest<F>
impl<F> UnwindSafe for SelectKBest<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 more