Skip to main content

RidgeClassifier

Struct RidgeClassifier 

Source
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 (f32 or f64).

Fields§

§alpha: F

Regularization strength. Larger values specify stronger regularization.

§fit_intercept: bool

Whether 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: F

Convergence 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: bool

When 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>

Source

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).

Source

pub fn with_alpha(self, alpha: F) -> Self

Set the regularization strength.

Source

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

Set whether to fit an intercept term.

Source

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.

Source

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.

Source

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.

Source

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>

Source

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

Trait Implementations§

Source§

impl<F: Clone> Clone for RidgeClassifier<F>

Source§

fn clone(&self) -> RidgeClassifier<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 RidgeClassifier<F>

Source§

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

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

impl<F: Float> Default for RidgeClassifier<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<usize>, Dim<[usize; 1]>>> for RidgeClassifier<F>

Source§

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

type Fitted = FittedRidgeClassifier<F>

The fitted model type returned by fit.
Source§

type Error = FerroError

The error type returned by 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> 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