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 (f32orf64).
Fields§
§fit_intercept: boolWhether to fit an intercept (bias) term.
copy_x: boolWhether 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: boolWhen 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>
impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + LinalgFloat + 'static> LinearRegression<F>
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>
impl<F: Float> LinearRegression<F>
Sourcepub fn new() -> Self
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).
Sourcepub fn with_fit_intercept(self, fit_intercept: bool) -> Self
pub fn with_fit_intercept(self, fit_intercept: bool) -> Self
Set whether to fit an intercept term.
Sourcepub fn with_copy_x(self, copy_x: bool) -> Self
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.
Sourcepub fn with_n_jobs(self, n_jobs: Option<usize>) -> Self
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.
Sourcepub fn with_positive(self, positive: bool) -> Self
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>
impl<F: Clone> Clone for LinearRegression<F>
Source§fn clone(&self) -> LinearRegression<F>
fn clone(&self) -> LinearRegression<F>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for LinearRegression<F>
impl<F: Debug> Debug for LinearRegression<F>
Source§impl<F: Float> Default for LinearRegression<F>
impl<F: Float> Default for LinearRegression<F>
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>
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>
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>
type Fitted = FittedLinearRegression<F>
fit.Source§type Error = FerroError
type Error = FerroError
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>
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>
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>
type Fitted = FittedMultiOutputLinearRegression<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl<F> PipelineEstimator<F> for LinearRegression<F>
impl<F> PipelineEstimator<F> for LinearRegression<F>
Source§fn fit_pipeline(
&self,
x: &Array2<F>,
y: &Array1<F>,
) -> Result<Box<dyn FittedPipelineEstimator<F>>, FerroError>
fn fit_pipeline( &self, x: &Array2<F>, y: &Array1<F>, ) -> Result<Box<dyn FittedPipelineEstimator<F>>, FerroError>
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
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>
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>
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