#[non_exhaustive]pub struct ElasticNet { /* private fields */ }Expand description
ElasticNet regression (mixed L1 + L2 regularization).
Uses coordinate descent to minimize:
(1 / 2n) ‖y − Xβ − β₀‖² + α × l1_ratio × ‖β‖₁ + α × (1 − l1_ratio) / 2 × ‖β‖²§Example
use scry_learn::dataset::Dataset;
use scry_learn::linear::ElasticNet;
let features = vec![vec![1.0, 2.0, 3.0, 4.0, 5.0]];
let target = vec![2.1, 4.0, 5.9, 8.1, 10.0];
let data = Dataset::new(features, target, vec!["x".into()], "y");
let mut model = ElasticNet::new().alpha(0.1).l1_ratio(0.5);
model.fit(&data).unwrap();
let preds = model.predict(&[vec![3.0]]).unwrap();Implementations§
Source§impl ElasticNet
impl ElasticNet
Sourcepub fn fit(&mut self, data: &Dataset) -> Result<()>
pub fn fit(&mut self, data: &Dataset) -> Result<()>
Fit the ElasticNet model using coordinate descent.
Sourcepub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
pub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>
Predict target values for new samples.
features is row-major: features[sample_idx][feature_idx].
Sourcepub fn fit_sparse(&mut self, features: &CscMatrix, target: &[f64]) -> Result<()>
pub fn fit_sparse(&mut self, features: &CscMatrix, target: &[f64]) -> Result<()>
Fit on sparse features using coordinate descent.
Sourcepub fn predict_sparse(&self, features: &CsrMatrix) -> Result<Vec<f64>>
pub fn predict_sparse(&self, features: &CsrMatrix) -> Result<Vec<f64>>
Predict from sparse features (CSR format).
Sourcepub fn coefficients(&self) -> &[f64]
pub fn coefficients(&self) -> &[f64]
Get learned coefficients.
Trait Implementations§
Source§impl Clone for ElasticNet
impl Clone for ElasticNet
Source§fn clone(&self) -> ElasticNet
fn clone(&self) -> ElasticNet
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ElasticNet
impl Debug for ElasticNet
Source§impl Default for ElasticNet
impl Default for ElasticNet
Source§impl PipelineModel for ElasticNet
impl PipelineModel for ElasticNet
Auto Trait Implementations§
impl Freeze for ElasticNet
impl RefUnwindSafe for ElasticNet
impl Send for ElasticNet
impl Sync for ElasticNet
impl Unpin for ElasticNet
impl UnsafeUnpin for ElasticNet
impl UnwindSafe for ElasticNet
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 more