Struct linfa_elasticnet::ElasticNetParams [−][src]
Linear regression with both L1 and L2 regularization
Configures and minimizes the following objective function: 1 / (2 * n_samples) * ||y - Xw||^2_2 + penalty * l1_ratio * ||w||_1 + 0.5 * penalty * (1 - l1_ratio) * ||w||^2_2
Fields
penalty: F
l1_ratio: F
with_intercept: bool
max_iterations: u32
tolerance: F
Implementations
impl<F: Float> ElasticNetParams<F>
[src]
AbsDiffEq + Float + FromPrimitive + ScalarOperand + NumAssignOps> Configure and fit a Elastic Net model
pub fn new() -> ElasticNetParams<F>
[src]
Create default elastic net hyper parameters
By default, an intercept will be fitted. To disable fitting an
intercept, call .with_intercept(false)
before calling .fit()
.
To additionally normalize the feature matrix before fitting, call
fit_intercept_and_normalize()
before calling fit()
. The feature
matrix will not be normalized by default.
pub fn penalty(self, penalty: F) -> Self
[src]
Set the overall parameter penalty parameter of the elastic net.
Use l1_ratio
to configure how the penalty distributed to L1 and L2
regularization.
pub fn l1_ratio(self, l1_ratio: F) -> Self
[src]
Set l1_ratio parameter of the elastic net. Controls how the parameter
penalty is distributed to L1 and L2 regularization.
Setting l1_ratio
to 1.0 is equivalent to a “Lasso” penalization,
setting it to 0.0 is equivalent to “Ridge” penalization.
Defaults to 0.5
if not set
l1_ratio
must be between 0.0
and 1.0
.
pub fn with_intercept(self, with_intercept: bool) -> Self
[src]
Configure the elastic net model to fit an intercept.
Defaults to true
if not set.
pub fn tolerance(self, tolerance: F) -> Self
[src]
Set the tolerance which is the minimum absolute change in any of the model parameters needed for the parameter optimization to continue.
Defaults to 1e-4
if not set
pub fn max_iterations(self, max_iterations: u32) -> Self
[src]
Set the maximum number of iterations for the optimization routine.
Defaults to 1000
if not set
pub fn compute_intercept<'a>(
&self,
y: ArrayView1<'a, F>
) -> (F, CowArray<'a, F, Ix1>)
[src]
&self,
y: ArrayView1<'a, F>
) -> (F, CowArray<'a, F, Ix1>)
Compute the intercept as the mean of y
and center y
if an intercept should
be used, use 0.0
as intercept and leave y
unchanged otherwise.
pub fn validate_params(&self) -> Result<()>
[src]
Validate the hyper parameters
This function is called in Self::fit
and validates all hyper parameters
Trait Implementations
impl<'a, F, D, T> Fit<'a, ArrayBase<D, Dim<[usize; 2]>>, T> for ElasticNetParams<F> where
F: Float + AbsDiffEq + Lapack,
D: Data<Elem = F>,
T: AsTargets<Elem = F>,
[src]
F: Float + AbsDiffEq + Lapack,
D: Data<Elem = F>,
T: AsTargets<Elem = F>,
type Object = Result<ElasticNet<F>>
fn fit(
&self,
dataset: &DatasetBase<ArrayBase<D, Ix2>, T>
) -> Result<ElasticNet<F>>
[src]
&self,
dataset: &DatasetBase<ArrayBase<D, Ix2>, T>
) -> Result<ElasticNet<F>>
Fit an elastic net model given a feature matrix x
and a target
variable y
.
The feature matrix x
must have shape (n_samples, n_features)
The target variable y
must have shape (n_samples)
Returns a FittedElasticNet
object which contains the fitted
parameters and can be used to predict
values of the target variable
for new feature values.
Auto Trait Implementations
impl<F> RefUnwindSafe for ElasticNetParams<F> where
F: RefUnwindSafe,
F: RefUnwindSafe,
impl<F> Send for ElasticNetParams<F> where
F: Send,
F: Send,
impl<F> Sync for ElasticNetParams<F> where
F: Sync,
F: Sync,
impl<F> Unpin for ElasticNetParams<F> where
F: Unpin,
F: Unpin,
impl<F> UnwindSafe for ElasticNetParams<F> where
F: UnwindSafe,
F: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,