pub struct PolynomialFeatures<State = Untrained> {
pub degree: u32,
pub interaction_only: bool,
pub include_bias: bool,
/* private fields */
}Expand description
Polynomial feature expansion
Generate polynomial and interaction features up to a given degree. For example, if the input has features [a, b], degree 2 gives: [1, a, b, a^2, ab, b^2]
§Parameters
degree- Maximum degree of polynomial features (default: 2)interaction_only- Include only interaction features (default: false)include_bias- Include bias column (default: true)
§Examples
ⓘ
use sklears_kernel_approximation::polynomial_features::PolynomialFeatures;
use sklears_core::traits::{Transform, Fit, Untrained}
use scirs2_core::ndarray::array;
let X = array![[1.0, 2.0], [3.0, 4.0]];
let poly = PolynomialFeatures::new(2);
let fitted_poly = poly.fit(&X, &()).unwrap();
let X_transformed = fitted_poly.transform(&X).unwrap();
// Features: [1, a, b, a^2, ab, b^2] = 6 features
assert_eq!(X_transformed.shape(), &[2, 6]);PolynomialFeatures
Fields§
§degree: u32Maximum degree of polynomial features
interaction_only: boolInclude only interaction features
include_bias: boolInclude bias column
Implementations§
Source§impl PolynomialFeatures<Untrained>
impl PolynomialFeatures<Untrained>
Sourcepub fn interaction_only(self, interaction_only: bool) -> Self
pub fn interaction_only(self, interaction_only: bool) -> Self
Set interaction_only parameter
Sourcepub fn include_bias(self, include_bias: bool) -> Self
pub fn include_bias(self, include_bias: bool) -> Self
Set include_bias parameter
Source§impl PolynomialFeatures<Trained>
impl PolynomialFeatures<Trained>
Sourcepub fn n_input_features(&self) -> usize
pub fn n_input_features(&self) -> usize
Get the number of input features
Sourcepub fn n_output_features(&self) -> usize
pub fn n_output_features(&self) -> usize
Get the number of output features
Trait Implementations§
Source§impl<State: Clone> Clone for PolynomialFeatures<State>
impl<State: Clone> Clone for PolynomialFeatures<State>
Source§fn clone(&self) -> PolynomialFeatures<State>
fn clone(&self) -> PolynomialFeatures<State>
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<State: Debug> Debug for PolynomialFeatures<State>
impl<State: Debug> Debug for PolynomialFeatures<State>
Source§impl Estimator for PolynomialFeatures<Untrained>
impl Estimator for PolynomialFeatures<Untrained>
Source§type Error = SklearsError
type Error = SklearsError
Error type for the estimator
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Validate estimator configuration with detailed error context
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Check if estimator is compatible with given data dimensions
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Get estimator metadata
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for PolynomialFeatures<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for PolynomialFeatures<Untrained>
Source§type Fitted = PolynomialFeatures<Trained>
type Fitted = PolynomialFeatures<Trained>
The fitted model type
Source§fn fit(self, x: &Array2<Float>, _y: &()) -> Result<Self::Fitted>
fn fit(self, x: &Array2<Float>, _y: &()) -> Result<Self::Fitted>
Fit the model to the provided data with validation
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Fit with custom validation and early stopping
Auto Trait Implementations§
impl<State> Freeze for PolynomialFeatures<State>
impl<State> RefUnwindSafe for PolynomialFeatures<State>where
State: RefUnwindSafe,
impl<State> Send for PolynomialFeatures<State>where
State: Send,
impl<State> Sync for PolynomialFeatures<State>where
State: Sync,
impl<State> Unpin for PolynomialFeatures<State>where
State: Unpin,
impl<State> UnwindSafe for PolynomialFeatures<State>where
State: 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> 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<T> StableApi for Twhere
T: Estimator,
impl<T> StableApi for Twhere
T: Estimator,
Source§const STABLE_SINCE: &'static str = "0.1.0"
const STABLE_SINCE: &'static str = "0.1.0"
API version this type was stabilized in
Source§const HAS_EXPERIMENTAL_FEATURES: bool = false
const HAS_EXPERIMENTAL_FEATURES: bool = false
Whether this API has any experimental features