Skip to main content

LinearRegression

Struct LinearRegression 

Source
pub struct LinearRegression<F> {
    pub fit_intercept: bool,
    pub copy_x: bool,
    pub n_jobs: Option<usize>,
    pub positive: bool,
    /* private fields */
}
Expand description

Ordinary least squares linear regression.

Solves the least-squares problem via a single SVD (minimum-norm, LAPACK-gelsd-equivalent, through ferray::linalg::lstsq). The fit_intercept option controls whether a bias (intercept) term is included.

§Type Parameters

  • F: The floating-point type (f32 or f64).

Fields§

§fit_intercept: bool

Whether to fit an intercept (bias) term.

§copy_x: bool

Whether X may be overwritten during fit (sklearn copy_X, _base.py:480). ferrolearn’s fit never mutates x (it reads via .iter()/.mean_axis()), so the observable non-mutation contract holds for either value; the field is exposed for ABI parity. Default true, matching sklearn (_base.py:572).

§n_jobs: Option<usize>

Number of jobs for the computation (sklearn n_jobs, _base.py:483). ferrolearn’s dense OLS solve is single-threaded, so this is stored but ignored — parallelism is a no-op here and behaviour matches sklearn’s n_jobs=None single-job default. Default None (_base.py:573).

§positive: bool

When true, constrains the fitted coefficients to be non-negative via non-negative least squares (sklearn positive, _base.py:574). sklearn solves the (centered, √w-rescaled) coefficient system with scipy.optimize.nnls instead of linalg.lstsq when positive=True (_base.py:645-647). Default false, matching sklearn’s positive=False (_base.py:574); when false, the fit is byte-identical to the unconstrained OLS path.

Implementations§

Source§

impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + LinalgFloat + 'static> LinearRegression<F>

Source

pub fn fit_with_sample_weight( &self, x: &Array2<F>, y: &Array1<F>, sample_weight: Option<&Array1<F>>, ) -> Result<FittedLinearRegression<F>, FerroError>

Source§

impl<F: Float> LinearRegression<F>

Source

pub fn new() -> Self

Create a new LinearRegression with default settings.

Defaults: fit_intercept = true, copy_x = true, n_jobs = None, positive = false (mirroring sklearn’s ctor defaults, _base.py:571-574).

Source

pub fn with_fit_intercept(self, fit_intercept: bool) -> Self

Set whether to fit an intercept term.

Source

pub fn with_copy_x(self, copy_x: bool) -> Self

Set the copy_X flag (sklearn copy_X, _base.py:480).

ferrolearn’s fit never mutates x, so this is exposed for ABI parity with sklearn and does not change the result.

Source

pub fn with_n_jobs(self, n_jobs: Option<usize>) -> Self

Set the n_jobs parameter (sklearn n_jobs, _base.py:483).

The dense OLS solve is single-threaded; this is stored but ignored.

Source

pub fn with_positive(self, positive: bool) -> Self

Set the positive flag (sklearn positive, _base.py:574).

When true, the fitted coefficients are constrained to be non-negative, solved via non-negative least squares (scipy.optimize.nnls, _base.py:647) instead of unconstrained OLS. Default false.

Trait Implementations§

Source§

impl<F: Clone> Clone for LinearRegression<F>

Source§

fn clone(&self) -> LinearRegression<F>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug> Debug for LinearRegression<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Float> Default for LinearRegression<F>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + LinalgFloat + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>> for LinearRegression<F>

Source§

fn fit( &self, x: &Array2<F>, y: &Array1<F>, ) -> Result<FittedLinearRegression<F>, FerroError>

Fit the linear regression model.

Solves the OLS least-squares problem via the SVD-based minimum-norm solver [crate::linalg::solve_lstsq] (routed through ferray::linalg::lstsq, LAPACK-gelsd-equivalent), matching scikit-learn’s dense path linalg.lstsq(X, y) (sklearn/linear_model/_base.py:687). When fit_intercept is true, X and y are centered first and the intercept is recovered as y_mean - x_mean . w.

§Errors

Returns FerroError::ShapeMismatch if the number of samples in x and y differ. Returns FerroError::InsufficientSamples if there are fewer samples than features. Returns FerroError::NumericalInstability if the system is singular.

Source§

type Fitted = FittedLinearRegression<F>

The fitted model type returned by fit.
Source§

type Error = FerroError

The error type returned by fit.
Source§

impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + LinalgFloat + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for LinearRegression<F>

Source§

fn fit( &self, x: &Array2<F>, y: &Array2<F>, ) -> Result<FittedMultiOutputLinearRegression<F>, FerroError>

Fit the multi-output linear regression model on a 2-D target Y.

Mirrors scikit-learn’s multi-output dense path: linalg.lstsq(X, Y) with Y of shape (n_samples, n_targets) solves all targets in one SVD, yielding coef_ of shape (n_targets, n_features) and a per-target intercept_ of shape (n_targets,) (sklearn/linear_model/_base.py:687, coef_.T; intercept _set_intercept, _base.py:308/:322). When fit_intercept is true, X and each column of Y are centered by their column means and the intercept is recovered as y_off − coefficients · x_off per target; when false, the solve runs on raw X/Y and the intercepts are all 0.

The 1-D Fit<Array2<F>, Array1<F>> impl is unaffected — this is an additive 2-D arm.

§Errors

Returns FerroError::ShapeMismatch if the number of samples in x and y differ. Returns FerroError::InsufficientSamples if there are no samples. Returns FerroError::NumericalInstability if the system is singular.

Source§

type Fitted = FittedMultiOutputLinearRegression<F>

The fitted model type returned by fit.
Source§

type Error = FerroError

The error type returned by fit.
Source§

impl<F> PipelineEstimator<F> for LinearRegression<F>
where F: Float + FromPrimitive + ScalarOperand + LinalgFloat + Send + Sync + 'static,

Source§

fn fit_pipeline( &self, x: &Array2<F>, y: &Array1<F>, ) -> Result<Box<dyn FittedPipelineEstimator<F>>, FerroError>

Fit this estimator on the given data. Read more

Auto Trait Implementations§

§

impl<F> Freeze for LinearRegression<F>

§

impl<F> RefUnwindSafe for LinearRegression<F>
where F: RefUnwindSafe,

§

impl<F> Send for LinearRegression<F>
where F: Send,

§

impl<F> Sync for LinearRegression<F>
where F: Sync,

§

impl<F> Unpin for LinearRegression<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for LinearRegression<F>

§

impl<F> UnwindSafe for LinearRegression<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V