pub struct RidgeClassifier<F> {
pub alpha: F,
pub fit_intercept: bool,
pub max_iter: Option<usize>,
pub tol: F,
pub positive: bool,
pub class_weight: ClassWeight<F>,
}Expand description
Ridge Classifier.
Applies Ridge regression (L2-regularized least squares) to classification by converting labels to a binary indicator matrix.
§Type Parameters
F: The floating-point type (f32orf64).
Fields§
§alpha: FRegularization strength. Larger values specify stronger regularization.
fit_intercept: boolWhether to fit an intercept (bias) term.
max_iter: Option<usize>Maximum number of iterations for iterative solvers (sklearn max_iter,
_ridge.py:1520). Exposed for sklearn ABI parity; ferrolearn implements
only the direct dense solver, so this field is stored but has no effect
on the computed result. Default None, matching sklearn’s default
(_ridge.py:1520).
tol: FConvergence tolerance for iterative solvers (sklearn tol,
_ridge.py:1521). Exposed for sklearn ABI parity; ferrolearn implements
only the direct dense solver, so this field is stored but has no effect
on the computed result. Default 1e-4, matching sklearn’s default
(_ridge.py:1521).
positive: boolWhen true, constrain the coefficients to be non-negative (sklearn
positive, _ridge.py:902/:911). The per-target indicator-ridge solve
is routed through projected coordinate descent
(crate::linalg::nonneg_ridge_cd) using max_iter/tol, mirroring the
optimum sklearn reaches with its L-BFGS-B solver for positive=True
(_ridge.py:329). Default false, matching sklearn (_ridge.py:902).
class_weight: ClassWeight<F>Per-class sample weighting (sklearn class_weight,
_ridge.py:1398). Reweights samples by class membership before the
weighted ridge fit, multiplying into any user sample_weight
(_ridge.py:1305-1307, mirroring
sklearn.utils.class_weight.compute_class_weight). Default
ClassWeight::None (all classes weight 1.0,
matching sklearn class_weight=None, _ridge.py:1400).
Implementations§
Source§impl<F: Float> RidgeClassifier<F>
impl<F: Float> RidgeClassifier<F>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new RidgeClassifier with default settings.
Defaults: alpha = 1.0, fit_intercept = true, max_iter = None,
tol = 1e-4, positive = false — mirroring sklearn’s ctor defaults
(sklearn/linear_model/_ridge.py:1514-1526, positive=False
_ridge.py:902).
Sourcepub fn with_alpha(self, alpha: F) -> Self
pub fn with_alpha(self, alpha: F) -> Self
Set the regularization strength.
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_max_iter(self, max_iter: Option<usize>) -> Self
pub fn with_max_iter(self, max_iter: Option<usize>) -> Self
Set the maximum number of iterations for iterative solvers (sklearn
max_iter, _ridge.py:1520).
ferrolearn’s direct solver solves in closed form with no iteration, so this is stored for sklearn ABI parity and does not affect the computed result.
Sourcepub fn with_tol(self, tol: F) -> Self
pub fn with_tol(self, tol: F) -> Self
Set the convergence tolerance for iterative solvers (sklearn tol,
_ridge.py:1521).
ferrolearn’s direct solver solves in closed form with no iteration, so this is stored for sklearn ABI parity and does not affect the computed result.
Sourcepub fn with_positive(self, positive: bool) -> Self
pub fn with_positive(self, positive: bool) -> Self
Constrain the fitted coefficients to be non-negative (sklearn
positive, _ridge.py:902/:911).
When true, each indicator-target ridge solve is routed through
projected coordinate descent (crate::linalg::nonneg_ridge_cd) using
max_iter/tol, yielding the same optimum sklearn reaches with its
L-BFGS-B solver for positive=True (_ridge.py:329). false (default)
is byte-identical to the unconstrained closed-form path.
Sourcepub fn with_class_weight(self, class_weight: ClassWeight<F>) -> Self
pub fn with_class_weight(self, class_weight: ClassWeight<F>) -> Self
Set the per-class sample weighting strategy (sklearn class_weight,
_ridge.py:1398).
The selected per-class weight reweights samples by class membership and
multiplies into any user sample_weight before the weighted ridge fit
(_ridge.py:1305-1307, mirroring
sklearn.utils.class_weight.compute_class_weight). ClassWeight::None
(default) leaves the unweighted fit byte-identical.
Source§impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + LinalgFloat + 'static> RidgeClassifier<F>
impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + LinalgFloat + 'static> RidgeClassifier<F>
Sourcepub fn fit_with_sample_weight(
&self,
x: &Array2<F>,
y: &Array1<usize>,
sample_weight: Option<&Array1<F>>,
) -> Result<FittedRidgeClassifier<F>, FerroError>
pub fn fit_with_sample_weight( &self, x: &Array2<F>, y: &Array1<usize>, sample_weight: Option<&Array1<F>>, ) -> Result<FittedRidgeClassifier<F>, FerroError>
Fit the Ridge Classifier with optional per-sample weights.
Mirrors scikit-learn’s RidgeClassifier.fit(X, y, sample_weight=None)
(sklearn/linear_model/_ridge.py:1220). The target is encoded as an
indicator matrix Y (binary {-1, +1} single column, multiclass
one-hot) via LabelBinarizer(pos_label=1, neg_label=-1)
(_ridge.py:1300-1301), then the underlying weighted ridge is solved on
(X, Y): sample_weight is forwarded into _BaseRidge.fit which does
weighted _preprocess_data (weighted offsets) + _rescale_data (√w
row-rescale, _ridge.py:682-688).
When sample_weight is Some(w) and fit_intercept is true, the
weighted offsets x_off[j] = Σᵢ wᵢ·x[i,j] / Σwᵢ,
y_off[t] = Σᵢ wᵢ·Y[i,t] / Σwᵢ center X/Y, then each row is rescaled
by √wᵢ before the per-target ridge solve, and
intercept[t] = y_off[t] − Σⱼ x_off[j]·coef[j,t]. With fit_intercept
false only the √w row-rescale is applied and the intercept is 0.
sample_weight = None is BYTE-IDENTICAL to Fit::fit (the unweighted
centering + per-target linalg::solve_ridge path).
§Errors
FerroError::ShapeMismatch— sample count mismatch, orsample_weight.len() != n_samples.FerroError::InvalidParameter— negative alpha.FerroError::InsufficientSamples— fewer than 2 classes / no samples.
Trait Implementations§
Source§impl<F: Clone> Clone for RidgeClassifier<F>
impl<F: Clone> Clone for RidgeClassifier<F>
Source§fn clone(&self) -> RidgeClassifier<F>
fn clone(&self) -> RidgeClassifier<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 RidgeClassifier<F>
impl<F: Debug> Debug for RidgeClassifier<F>
Source§impl<F: Float> Default for RidgeClassifier<F>
impl<F: Float> Default for RidgeClassifier<F>
Source§impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + LinalgFloat + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>> for RidgeClassifier<F>
impl<F: Float + Send + Sync + ScalarOperand + FromPrimitive + LinalgFloat + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>> for RidgeClassifier<F>
Source§fn fit(
&self,
x: &Array2<F>,
y: &Array1<usize>,
) -> Result<FittedRidgeClassifier<F>, FerroError>
fn fit( &self, x: &Array2<F>, y: &Array1<usize>, ) -> Result<FittedRidgeClassifier<F>, FerroError>
Fit the Ridge Classifier by converting labels to a binary indicator matrix and solving multivariate Ridge regression.
Equivalent to RidgeClassifier::fit_with_sample_weight with
sample_weight = None.
§Errors
FerroError::ShapeMismatch— sample count mismatch.FerroError::InvalidParameter— negative alpha.FerroError::InsufficientSamples— fewer than 2 classes.
Source§type Fitted = FittedRidgeClassifier<F>
type Fitted = FittedRidgeClassifier<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Auto Trait Implementations§
impl<F> Freeze for RidgeClassifier<F>where
F: Freeze,
impl<F> RefUnwindSafe for RidgeClassifier<F>where
F: RefUnwindSafe,
impl<F> Send for RidgeClassifier<F>where
F: Send,
impl<F> Sync for RidgeClassifier<F>where
F: Sync,
impl<F> Unpin for RidgeClassifier<F>where
F: Unpin,
impl<F> UnsafeUnpin for RidgeClassifier<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for RidgeClassifier<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