pub struct Ridge { /* private fields */ }Expand description
Ridge regression with L2 regularization.
use datarust::linear_model::Ridge;
use datarust::traits::Predictor;
use datarust::Matrix;
let x = Matrix::new(vec![
vec![0.0, 0.0],
vec![1.0, 1.0],
vec![2.0, 2.0],
vec![3.0, 3.0],
])?;
// Collinear features: LinearRegression would be singular; Ridge handles it.
let y = vec![1.0, 2.0, 3.0, 4.0];
let mut model = Ridge::new().with_alpha(1.0);
model.fit(&x, &y)?;
let pred = model.predict(&x)?;
assert_eq!(pred.len(), 4);Implementations§
Source§impl Ridge
impl Ridge
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Ridge with alpha = 1.0, fit_intercept = true,
solver = Cholesky.
Sourcepub fn with_alpha(self, alpha: f64) -> Self
pub fn with_alpha(self, alpha: f64) -> Self
Builder: regularization strength alpha (default 1.0). Larger values
shrink coefficients more aggressively. Must be >= 0.
Sourcepub fn with_fit_intercept(self, b: bool) -> Self
pub fn with_fit_intercept(self, b: bool) -> Self
Builder: whether to fit an intercept term (default true).
Sourcepub fn with_solver(self, s: RidgeSolver) -> Self
pub fn with_solver(self, s: RidgeSolver) -> Self
Builder: choose the solver (default RidgeSolver::Cholesky).
Sourcepub fn n_features_in(&self) -> usize
pub fn n_features_in(&self) -> usize
Number of features seen during fit.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Ridge
impl<'de> Deserialize<'de> for Ridge
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Estimator for Ridge
Source§impl Predictor for Ridge
impl Predictor for Ridge
Source§fn fit(&mut self, x: &Matrix, y: &[f64]) -> Result<()>
fn fit(&mut self, x: &Matrix, y: &[f64]) -> Result<()>
Fit the estimator on training features and target values.
Auto Trait Implementations§
impl Freeze for Ridge
impl RefUnwindSafe for Ridge
impl Send for Ridge
impl Sync for Ridge
impl Unpin for Ridge
impl UnsafeUnpin for Ridge
impl UnwindSafe for Ridge
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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