pub struct ElasticNetCV<F> { /* private fields */ }Expand description
ElasticNet regression with built-in cross-validation for joint
(alpha, l1_ratio) selection.
For each candidate l1_ratio, the module generates a log-spaced alpha
grid (from alpha_max down to alpha_max * 1e-3) or uses the
user-supplied grid, runs k-fold CV, and selects the combination that
minimises mean squared error.
§Type Parameters
F: The floating-point type (f32orf64).
Implementations§
Source§impl<F: Float + FromPrimitive> ElasticNetCV<F>
impl<F: Float + FromPrimitive> ElasticNetCV<F>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ElasticNetCV with default settings.
Defaults:
l1_ratios = [0.1, 0.5, 0.7, 0.9, 0.95, 0.99, 1.0]n_alphas = 100cv = 5max_iter = 1000tol = 1e-4fit_intercept = true
Sourcepub fn with_l1_ratios(self, l1_ratios: Vec<F>) -> Self
pub fn with_l1_ratios(self, l1_ratios: Vec<F>) -> Self
Set the candidate L1/L2 mixing ratios.
Each value must be in [0.0, 1.0].
Sourcepub fn with_n_alphas(self, n_alphas: usize) -> Self
pub fn with_n_alphas(self, n_alphas: usize) -> Self
Set the number of alphas generated per l1_ratio.
Sourcepub fn with_cv(self, cv: usize) -> Self
pub fn with_cv(self, cv: usize) -> Self
Set the number of cross-validation folds.
Must be at least 2.
Sourcepub fn with_max_iter(self, max_iter: usize) -> Self
pub fn with_max_iter(self, max_iter: usize) -> Self
Set the maximum number of coordinate descent iterations.
Sourcepub fn with_fit_intercept(self, fit_intercept: bool) -> Self
pub fn with_fit_intercept(self, fit_intercept: bool) -> Self
Set whether to fit an intercept term.
Trait Implementations§
Source§impl<F: Clone> Clone for ElasticNetCV<F>
impl<F: Clone> Clone for ElasticNetCV<F>
Source§fn clone(&self) -> ElasticNetCV<F>
fn clone(&self) -> ElasticNetCV<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for ElasticNetCV<F>
impl<F: Debug> Debug for ElasticNetCV<F>
Source§impl<F: Float + FromPrimitive> Default for ElasticNetCV<F>
impl<F: Float + FromPrimitive> Default for ElasticNetCV<F>
Source§impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for ElasticNetCV<F>
impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for ElasticNetCV<F>
Source§fn fit(
&self,
x: &Array2<F>,
y: &Array1<F>,
) -> Result<FittedElasticNetCV<F>, FerroError>
fn fit( &self, x: &Array2<F>, y: &Array1<F>, ) -> Result<FittedElasticNetCV<F>, FerroError>
Fit the ElasticNetCV model.
For each candidate l1_ratio, generates an alpha grid, runs k-fold
CV for every (alpha, l1_ratio) pair, then refits on the full data
using the best combination.
§Errors
FerroError::ShapeMismatchifxandysizes differ.FerroError::InvalidParameterifl1_ratiosis empty, any ratio is outside[0, 1],cv < 2, orn_alphas == 0.FerroError::InsufficientSamplesifn_samples < cv.
Source§type Fitted = FittedElasticNetCV<F>
type Fitted = FittedElasticNetCV<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Auto Trait Implementations§
impl<F> Freeze for ElasticNetCV<F>where
F: Freeze,
impl<F> RefUnwindSafe for ElasticNetCV<F>where
F: RefUnwindSafe,
impl<F> Send for ElasticNetCV<F>where
F: Send,
impl<F> Sync for ElasticNetCV<F>where
F: Sync,
impl<F> Unpin for ElasticNetCV<F>where
F: Unpin,
impl<F> UnsafeUnpin for ElasticNetCV<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for ElasticNetCV<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
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>
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>
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