Skip to main content

ColumnTransformer

Struct ColumnTransformer 

Source
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

Source

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 (Drop or Passthrough).

Trait Implementations§

Source§

impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for ColumnTransformer

Source§

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::InvalidParameter if any column index is out of range.
  • Propagates any error returned by an individual transformer’s fit_pipeline call.
Source§

type Fitted = FittedColumnTransformer

The fitted model type returned by fit.
Source§

type Error = FerroError

The error type returned by fit.
Source§

impl PipelineTransformer<f64> for ColumnTransformer

Source§

fn fit_pipeline( &self, x: &Array2<f64>, _y: &Array1<f64>, ) -> Result<Box<dyn FittedPipelineTransformer<f64>>, FerroError>

Fit the column transformer using the pipeline interface.

The y argument is ignored; it exists only for API compatibility.

§Errors

Propagates errors from Fit::fit.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

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 SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,