#[non_exhaustive]pub struct LassoRegression { /* private fields */ }Expand description
Lasso regression (L1-regularized linear regression).
Uses coordinate descent to find the coefficients β that minimize:
(1 / 2n) ‖y − Xβ − β₀‖² + α ‖β‖₁Higher alpha produces sparser models (more coefficients driven to zero).
§Example
use scry_learn::dataset::Dataset;
use scry_learn::linear::LassoRegression;
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 lasso = LassoRegression::new().alpha(0.1);
lasso.fit(&data).unwrap();
let preds = lasso.predict(&[vec![3.0]]).unwrap();Implementations§
Source§impl LassoRegression
impl LassoRegression
Sourcepub fn fit(&mut self, data: &Dataset) -> Result<()>
pub fn fit(&mut self, data: &Dataset) -> Result<()>
Fit the Lasso 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.
Accepts CscMatrix for efficient column-oriented 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 LassoRegression
impl Clone for LassoRegression
Source§fn clone(&self) -> LassoRegression
fn clone(&self) -> LassoRegression
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 LassoRegression
impl Debug for LassoRegression
Source§impl Default for LassoRegression
impl Default for LassoRegression
Source§impl PipelineModel for LassoRegression
impl PipelineModel for LassoRegression
Auto Trait Implementations§
impl Freeze for LassoRegression
impl RefUnwindSafe for LassoRegression
impl Send for LassoRegression
impl Sync for LassoRegression
impl Unpin for LassoRegression
impl UnsafeUnpin for LassoRegression
impl UnwindSafe for LassoRegression
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