Type Alias linfa_elasticnet::ElasticNetParams
source · pub type ElasticNetParams<F> = ElasticNetParamsBase<F, false>;
Expand description
A hyper-parameter set for Elastic-Net
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
The parameter set can be verified into a
ElasticNetValidParams
by calling
ParamGuard::check. It is also possible to directly fit a model with
Fit::fit which implicitely verifies the parameter set prior to the
model estimation and forwards any error.
Parameters
Name | Default | Purpose | Range |
---|---|---|---|
penalty | 1.0 | Overall parameter penalty | [0, inf) |
l1_ratio | 0.5 | Distribution of penalty to L1 and L2 regularizations | [0.0, 1.0] |
with_intercept | true | Enable intercept | false , true |
tolerance | 1e-4 | Absolute change of any of the parameters | (0, inf) |
max_iterations | 1000 | Maximum number of iterations | [1, inf) |
Errors
The following errors can come from invalid hyper-parameters:
Returns InvalidPenalty
if the penalty is negative.
Returns InvalidL1Ratio
if the L1 ratio is not in unit.
range
Returns InvalidTolerance
if the tolerance is negative.
Example
use linfa_elasticnet::{ElasticNetParams, ElasticNetError};
use linfa::prelude::*;
use ndarray::array;
let ds = Dataset::new(array![[1.0, 0.0], [0.0, 1.0]], array![3.0, 2.0]);
// create a new parameter set with penalty equals `1e-5`
let unchecked_params = ElasticNetParams::new()
.penalty(1e-5);
// fit model with unchecked parameter set
let model = unchecked_params.fit(&ds)?;
// transform into a verified parameter set
let checked_params = unchecked_params.check()?;
// Regenerate model with the verified parameters, this only returns
// errors originating from the fitting process
let model = checked_params.fit(&ds)?;
Aliased Type§
struct ElasticNetParams<F>(/* private fields */);