pub struct LinearRegression { /* private fields */ }Expand description
Ordinary least-squares linear regression.
Estimates y ≈ Xβ + b by minimising the residual sum of squares.
use datarust::linear_model::LinearRegression;
use datarust::traits::Predictor;
use datarust::Matrix;
let x = Matrix::new(vec![
vec![1.0, 2.0],
vec![2.0, 1.0],
vec![3.0, 4.0],
vec![4.0, 3.0],
])?;
let y = vec![5.0, 5.0, 11.0, 11.0];
let mut model = LinearRegression::new();
model.fit(&x, &y)?;
let pred = model.predict(&x)?;
assert!(pred.iter().zip(y.iter()).all(|(p, &t)| (p - t).abs() < 1e-9));Implementations§
Source§impl LinearRegression
impl LinearRegression
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new estimator with defaults: fit_intercept = true,
solver = Cholesky.
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: LinearSolver) -> Self
pub fn with_solver(self, s: LinearSolver) -> Self
Builder: choose the solver (default LinearSolver::Cholesky).
Sourcepub fn coef(&self) -> &[f64]
pub fn coef(&self) -> &[f64]
Fitted coefficients β, one entry per feature. Empty if not fitted.
Sourcepub fn n_features_in(&self) -> usize
pub fn n_features_in(&self) -> usize
Number of features seen during fit.
Trait Implementations§
Source§impl Clone for LinearRegression
impl Clone for LinearRegression
Source§fn clone(&self) -> LinearRegression
fn clone(&self) -> LinearRegression
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 LinearRegression
impl Debug for LinearRegression
Source§impl Default for LinearRegression
impl Default for LinearRegression
Source§impl<'de> Deserialize<'de> for LinearRegression
impl<'de> Deserialize<'de> for LinearRegression
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 LinearRegression
Source§impl Predictor for LinearRegression
impl Predictor for LinearRegression
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.
Source§impl Regressor for LinearRegression
impl Regressor for LinearRegression
Auto Trait Implementations§
impl Freeze for LinearRegression
impl RefUnwindSafe for LinearRegression
impl Send for LinearRegression
impl Sync for LinearRegression
impl Unpin for LinearRegression
impl UnsafeUnpin for LinearRegression
impl UnwindSafe for LinearRegression
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