#[non_exhaustive]pub struct LogisticRegression { /* private fields */ }Expand description
Logistic regression for binary/multiclass classification.
Uses L-BFGS (default) or gradient descent with configurable learning rate, iterations, and L2 regularization.
Implementations§
Source§impl LogisticRegression
impl LogisticRegression
Sourcepub fn learning_rate(self, lr: f64) -> Self
pub fn learning_rate(self, lr: f64) -> Self
Set the learning rate (used by GradientDescent solver only).
Sourcepub fn alpha(self, a: f64) -> Self
pub fn alpha(self, a: f64) -> Self
Set regularization strength (equivalent to 1/C in scikit-learn).
The meaning depends on the Penalty:
L2/L1— multiplier on the penalty termElasticNet— total regularization strength (split by l1_ratio)None— ignored
To match scikit-learn’s LogisticRegression(C=x), use alpha(1.0 / x).
The default alpha = 1.0 corresponds to C = 1.0.
Sourcepub fn penalty(self, p: Penalty) -> Self
pub fn penalty(self, p: Penalty) -> Self
Set the regularization penalty.
Default is Penalty::L2. Use Penalty::L1 for sparse feature selection.
§Errors
L1 and ElasticNet are not supported with the Lbfgs solver — calling
fit() will return Err(InvalidParameter). Switch to GradientDescent.
Sourcepub fn class_weight(self, cw: ClassWeight) -> Self
pub fn class_weight(self, cw: ClassWeight) -> Self
Set class weighting strategy for imbalanced datasets.
Sourcepub fn solver(self, s: Solver) -> Self
pub fn solver(self, s: Solver) -> Self
Set the solver algorithm.
Defaults to Solver::Lbfgs which is ~10-20× faster than gradient descent.
Sourcepub fn fit(&mut self, data: &Dataset) -> Result<()>
pub fn fit(&mut self, data: &Dataset) -> Result<()>
Train the model using the configured solver.
Uses consistent softmax for both training and inference (not one-vs-rest sigmoid).
§Errors
Returns InvalidParameter if Penalty::L1 or Penalty::ElasticNet is used
with the Lbfgs solver (L-BFGS requires a differentiable objective).
Sourcepub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>
pub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<Vec<f64>>>
Predict class probabilities.
Sourcepub fn fit_sparse(&mut self, features: &CscMatrix, target: &[f64]) -> Result<()>
pub fn fit_sparse(&mut self, features: &CscMatrix, target: &[f64]) -> Result<()>
Fit on sparse features using gradient descent.
Accepts CscMatrix (column-oriented) for efficient gradient computation.
Only supports L2 penalty (or None). Uses gradient descent (not L-BFGS).
Sourcepub fn predict_sparse(&self, features: &CsrMatrix) -> Result<Vec<f64>>
pub fn predict_sparse(&self, features: &CsrMatrix) -> Result<Vec<f64>>
Predict class labels from sparse features (CSR format).
Trait Implementations§
Source§impl CalibrableClassifier for LogisticRegression
impl CalibrableClassifier for LogisticRegression
Source§impl Clone for LogisticRegression
impl Clone for LogisticRegression
Source§fn clone(&self) -> LogisticRegression
fn clone(&self) -> LogisticRegression
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for LogisticRegression
impl Default for LogisticRegression
Source§impl PartialFit for LogisticRegression
impl PartialFit for LogisticRegression
Source§fn partial_fit(&mut self, data: &Dataset) -> Result<()>
fn partial_fit(&mut self, data: &Dataset) -> Result<()>
Run one pass of gradient descent on the given batch.
On the first call, initializes weights from the data dimensions and class count. Subsequent calls preserve weights and continue updating.
Source§fn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
partial_fit call).Source§impl PipelineModel for LogisticRegression
impl PipelineModel for LogisticRegression
Auto Trait Implementations§
impl Freeze for LogisticRegression
impl RefUnwindSafe for LogisticRegression
impl Send for LogisticRegression
impl Sync for LogisticRegression
impl Unpin for LogisticRegression
impl UnsafeUnpin for LogisticRegression
impl UnwindSafe for LogisticRegression
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> 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