pub struct ColumnTransformer { /* private fields */ }Expand description
An unfitted column transformer.
Applies each registered transformer to its designated column subset, then
horizontally concatenates all outputs. The Remainder policy controls
what happens to columns not covered by any transformer.
§Transformer order
Transformers are applied and their outputs concatenated in the order they
were registered. Remainder columns (when
remainder = Remainder::Passthrough) are appended last.
§Overlapping selections
Each transformer receives its own copy of the selected columns, so
overlapping ColumnSelectors are fully supported.
§Examples
use ferrolearn_preprocess::column_transformer::{
ColumnSelector, ColumnTransformer, Remainder,
};
use ferrolearn_preprocess::StandardScaler;
use ferrolearn_core::Fit;
use ferrolearn_core::Transform;
use ndarray::array;
let x = array![[1.0_f64, 10.0, 100.0], [2.0, 20.0, 200.0], [3.0, 30.0, 300.0]];
let ct = ColumnTransformer::new(
vec![("scaler".into(), Box::new(StandardScaler::<f64>::new()), ColumnSelector::Indices(vec![0, 1]))],
Remainder::Passthrough,
);
let fitted = ct.fit(&x, &()).unwrap();
let out = fitted.transform(&x).unwrap();
// 2 scaled columns + 1 passthrough column
assert_eq!(out.ncols(), 3);Implementations§
Source§impl ColumnTransformer
impl ColumnTransformer
Sourcepub fn new(
transformers: Vec<(String, Box<dyn PipelineTransformer<f64>>, ColumnSelector)>,
remainder: Remainder,
) -> Self
pub fn new( transformers: Vec<(String, Box<dyn PipelineTransformer<f64>>, ColumnSelector)>, remainder: Remainder, ) -> Self
Create a new ColumnTransformer.
§Parameters
transformers: A list of(name, transformer, selector)triples.remainder: Policy for uncovered columns (DroporPassthrough).
Trait Implementations§
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for ColumnTransformer
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for ColumnTransformer
Source§fn fit(
&self,
x: &Array2<f64>,
_y: &(),
) -> Result<FittedColumnTransformer, FerroError>
fn fit( &self, x: &Array2<f64>, _y: &(), ) -> Result<FittedColumnTransformer, FerroError>
Fit each transformer on its selected column subset.
Validates that all selected column indices are within bounds before fitting any transformer.
§Errors
FerroError::InvalidParameterif any column index is out of range.- Propagates any error returned by an individual transformer’s
fit_pipelinecall.
Source§type Fitted = FittedColumnTransformer
type Fitted = FittedColumnTransformer
The fitted model type returned by
fit.Source§type Error = FerroError
type Error = FerroError
The error type returned by
fit.Source§impl PipelineTransformer<f64> for ColumnTransformer
impl PipelineTransformer<f64> for ColumnTransformer
Source§fn fit_pipeline(
&self,
x: &Array2<f64>,
_y: &Array1<f64>,
) -> Result<Box<dyn FittedPipelineTransformer<f64>>, FerroError>
fn fit_pipeline( &self, x: &Array2<f64>, _y: &Array1<f64>, ) -> Result<Box<dyn FittedPipelineTransformer<f64>>, FerroError>
Auto Trait Implementations§
impl Freeze for ColumnTransformer
impl !RefUnwindSafe for ColumnTransformer
impl Send for ColumnTransformer
impl Sync for ColumnTransformer
impl Unpin for ColumnTransformer
impl UnsafeUnpin for ColumnTransformer
impl !UnwindSafe for ColumnTransformer
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> 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.