pub struct SplineTransformer<F> { /* private fields */ }Expand description
An unfitted spline transformer.
Calling Fit::fit computes the knot positions and returns a
FittedSplineTransformer that generates B-spline basis functions.
§Parameters
n_knots— number of interior knots (default 5).degree— degree of the B-spline (default 3, i.e. cubic).knots— knot placement strategy (defaultUniform).
The number of output columns per feature is n_knots + degree - 1.
§Examples
use ferrolearn_preprocess::spline_transformer::{SplineTransformer, KnotStrategy};
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::array;
let st = SplineTransformer::<f64>::new(5, 3, KnotStrategy::Uniform);
let x = array![[0.0], [0.25], [0.5], [0.75], [1.0]];
let fitted = st.fit(&x, &()).unwrap();
let out = fitted.transform(&x).unwrap();
// 5 + 3 - 1 = 7 basis columns per feature
assert_eq!(out.ncols(), 7);Implementations§
Source§impl<F: Float + Send + Sync + 'static> SplineTransformer<F>
impl<F: Float + Send + Sync + 'static> SplineTransformer<F>
Sourcepub fn new(n_knots: usize, degree: usize, knots: KnotStrategy) -> Self
pub fn new(n_knots: usize, degree: usize, knots: KnotStrategy) -> Self
Create a new SplineTransformer.
Sourcepub fn knot_strategy(&self) -> KnotStrategy
pub fn knot_strategy(&self) -> KnotStrategy
Return the knot placement strategy.
Trait Implementations§
Source§impl<F: Clone> Clone for SplineTransformer<F>
impl<F: Clone> Clone for SplineTransformer<F>
Source§fn clone(&self) -> SplineTransformer<F>
fn clone(&self) -> SplineTransformer<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 SplineTransformer<F>
impl<F: Debug> Debug for SplineTransformer<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for SplineTransformer<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for SplineTransformer<F>
Source§fn fit(
&self,
x: &Array2<F>,
_y: &(),
) -> Result<FittedSplineTransformer<F>, FerroError>
fn fit( &self, x: &Array2<F>, _y: &(), ) -> Result<FittedSplineTransformer<F>, FerroError>
Fit by computing knot positions for each feature.
§Errors
FerroError::InsufficientSamplesif the input has fewer than 2 rows.FerroError::InvalidParameterifn_knots< 2 ordegreeis 0.
Source§type Fitted = FittedSplineTransformer<F>
type Fitted = FittedSplineTransformer<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> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for SplineTransformer<F>
impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for SplineTransformer<F>
Source§fn fit_transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn fit_transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Source§type FitError = FerroError
type FitError = FerroError
The error type for the combined fit-transform operation.
Auto Trait Implementations§
impl<F> Freeze for SplineTransformer<F>
impl<F> RefUnwindSafe for SplineTransformer<F>where
F: RefUnwindSafe,
impl<F> Send for SplineTransformer<F>where
F: Send,
impl<F> Sync for SplineTransformer<F>where
F: Sync,
impl<F> Unpin for SplineTransformer<F>where
F: Unpin,
impl<F> UnsafeUnpin for SplineTransformer<F>
impl<F> UnwindSafe for SplineTransformer<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.