pub struct LogisticRegression {
pub coefficients: Vec<f64>,
pub fit_intercept: bool,
pub learning_rate: f64,
pub max_iterations: usize,
pub tolerance: f64,
pub lambda: f64,
}
Expand description
A simple logistic regression model with L2 regularization (optional). It uses batch gradient descent for training.
Fields§
§coefficients: Vec<f64>
Coefficients, including intercept as the first element:
coefficients[0]
= intercept
coefficients[1..]
= feature weights
fit_intercept: bool
§learning_rate: f64
§max_iterations: usize
§tolerance: f64
§lambda: f64
L2 regularization parameter (0.0 = no regularization).
Implementations§
Source§impl LogisticRegression
impl LogisticRegression
Sourcepub fn new(
fit_intercept: bool,
learning_rate: f64,
max_iterations: usize,
tolerance: f64,
lambda: f64,
) -> Self
pub fn new( fit_intercept: bool, learning_rate: f64, max_iterations: usize, tolerance: f64, lambda: f64, ) -> Self
Creates a new LogisticRegression model with default settings.
fit_intercept
: whether to fit an intercept termlearning_rate
: step size for gradient descentmax_iterations
: maximum number of gradient descent stepstolerance
: stopping criterion on coefficient updateslambda
: L2 regularization strength (0.0 = no regularization)
Sourcepub fn fit(&mut self, features: &[Vec<f64>], labels: &[f64])
pub fn fit(&mut self, features: &[Vec<f64>], labels: &[f64])
Fit the logistic regression model on the given data and binary labels (0 or 1).
§Arguments
features
: NxD data, N samples, D features eachlabels
: Nx1 binary labels (0.0 or 1.0)
§Panics
- If
features
is empty orlabels
length does not matchfeatures
length. - If any feature row has different length from the others.
- If labels are not 0.0 or 1.0 (though minor floating tolerances are allowed).
Sourcepub fn predict_proba_one(&self, features: &[f64]) -> f64
pub fn predict_proba_one(&self, features: &[f64]) -> f64
Predict the probability of label=1 for a single feature vector.
§Panics
- If
features
dimension doesn’t match the trained model.
Sourcepub fn predict_proba_batch(&self, features: &[Vec<f64>]) -> Vec<f64>
pub fn predict_proba_batch(&self, features: &[Vec<f64>]) -> Vec<f64>
Predict probabilities for multiple rows of features.
Sourcepub fn predict_one(&self, features: &[f64]) -> f64
pub fn predict_one(&self, features: &[f64]) -> f64
Predict a binary label (0 or 1) for a single feature vector, using threshold=0.5.
Trait Implementations§
Source§impl Clone for LogisticRegression
impl Clone for LogisticRegression
Source§fn clone(&self) -> LogisticRegression
fn clone(&self) -> LogisticRegression
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for LogisticRegression
impl RefUnwindSafe for LogisticRegression
impl Send for LogisticRegression
impl Sync for LogisticRegression
impl Unpin 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
Mutably borrows from an owned value. Read more
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>
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 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>
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