pub struct MultinomialLogisticRegression { /* private fields */ }Expand description
Multinomial (softmax) logistic regression over an ordered K >= 2 label set.
See the module documentation for the objective, the sklearn C relation, and the
deliberate omissions.
Implementations§
Source§impl MultinomialLogisticRegression
impl MultinomialLogisticRegression
Sourcepub fn new(n_classes: usize) -> MultinomialLogisticRegression
pub fn new(n_classes: usize) -> MultinomialLogisticRegression
Creates an unfitted head for n_classes classes.
n_classes is validated at fit time, not here, so that every rejection travels
through the same typed channel.
Sourcepub fn from_stored_coefficients(
ordered_labels: Vec<String>,
n_features: usize,
weights: Vec<f32>,
intercepts: Vec<f32>,
) -> Result<MultinomialLogisticRegression, HeadFitError>
pub fn from_stored_coefficients( ordered_labels: Vec<String>, n_features: usize, weights: Vec<f32>, intercepts: Vec<f32>, ) -> Result<MultinomialLogisticRegression, HeadFitError>
Rebuild a head from stored coefficients — the RELOAD door (plan 03-08).
§This is not a fit, and it does not claim to be one
Self::report stays None: no optimizer ran in this process, and a
synthesized report would assert a convergence status nobody observed. The
provenance of the coefficients belongs to whatever artifact carried them,
and it is that artifact’s job to record the fit that produced them.
Every input is validated before the head exists, through the SAME
label-set rule the fit path uses ([validate_label_set]) plus the
coefficient-arity and finiteness checks a fit cannot get wrong. A head
returned from here therefore satisfies predict_proba’s preconditions by
construction, exactly as a fitted one does.
§Errors
HeadFitError::InvalidInput carrying the offending
HeadInputError: too few classes, a mis-sized label map, an empty or
duplicated label, a zero feature dimension, a weight or intercept array of
the wrong length, or a non-finite coefficient.
Sourcepub fn with_max_iter(self, max_iter: usize) -> MultinomialLogisticRegression
pub fn with_max_iter(self, max_iter: usize) -> MultinomialLogisticRegression
Sets the maximum L-BFGS iteration budget (default DEFAULT_MAX_ITER).
Sourcepub fn with_tol(self, tol: f64) -> MultinomialLogisticRegression
pub fn with_tol(self, tol: f64) -> MultinomialLogisticRegression
Sets the gradient-norm convergence tolerance (default DEFAULT_TOL).
Sourcepub fn with_history_size(
self,
history_size: usize,
) -> MultinomialLogisticRegression
pub fn with_history_size( self, history_size: usize, ) -> MultinomialLogisticRegression
Sets the L-BFGS correction-pair history size (default DEFAULT_HISTORY_SIZE).
Sourcepub fn n_features(&self) -> Option<usize>
pub fn n_features(&self) -> Option<usize>
Fitted feature dimension, or None before a successful fit.
Sourcepub fn weights(&self) -> &[f32]
pub fn weights(&self) -> &[f32]
Fitted weights as K * d values in row-major order, or an empty slice.
Sourcepub fn intercepts(&self) -> &[f32]
pub fn intercepts(&self) -> &[f32]
Fitted intercepts (K values), or an empty slice.
Sourcepub fn report(&self) -> Option<&HeadFitReport>
pub fn report(&self) -> Option<&HeadFitReport>
Report from the last successful fit.
Sourcepub fn fit(
&mut self,
features: &[Vec<f32>],
class_indices: &[usize],
ordered_labels: &[String],
regularization: Regularization,
) -> Result<HeadFitReport, HeadFitError>
pub fn fit( &mut self, features: &[Vec<f32>], class_indices: &[usize], ordered_labels: &[String], regularization: Regularization, ) -> Result<HeadFitReport, HeadFitError>
Fits the head.
Returns the HeadFitReport on convergence, or a typed HeadFitError
otherwise. Non-convergence is an error, not a warning.
§A failed fit leaves the head UNFITTED
The fitted state is discarded on entry, before anything can fail. Otherwise a head
that fitted once and was then re-fitted with data the gate rejects would keep the
PREVIOUS fit’s weights, n_features, labels and report — so predict would answer
with a model the caller believes it failed to build, and report() would describe a
converged run that the last call did not perform. NotFitted is the honest answer
after a rejected fit, and it is only reachable if the state is cleared here.
Sourcepub fn predict_logits(
&self,
features: &[Vec<f32>],
) -> Result<Vec<Vec<f64>>, HeadFitError>
pub fn predict_logits( &self, features: &[Vec<f32>], ) -> Result<Vec<Vec<f64>>, HeadFitError>
Per-row class logits, accumulated in f64 from the f32 store.
THE single logit implementation: Self::predict_proba is this plus a
softmax, so a caller that needs both — VerifiedSetFitModel::classify,
which reports logits alongside probabilities — cannot obtain a pair
that disagrees with itself. Extracting it also removed the standing
temptation to write a second copy of the accumulation loop next to the
caller that wanted logits.
The accumulation ORDER is unchanged from the original predict_proba:
intercept first, then j ascending. That order is what the artifact
writer recorded its probe logits in, so it is load-bearing rather than
incidental.
Sourcepub fn predict_proba(
&self,
features: &[Vec<f32>],
) -> Result<Vec<Vec<f64>>, HeadFitError>
pub fn predict_proba( &self, features: &[Vec<f32>], ) -> Result<Vec<Vec<f64>>, HeadFitError>
Per-row class probabilities, computed with f64 logit accumulation.
Each returned row is finite and sums to 1 within 1e-6.
Sourcepub fn predict_indices(
&self,
features: &[Vec<f32>],
) -> Result<Vec<usize>, HeadFitError>
pub fn predict_indices( &self, features: &[Vec<f32>], ) -> Result<Vec<usize>, HeadFitError>
Per-row predicted class indices, breaking exact ties to the lowest index.
Trait Implementations§
Source§impl Clone for MultinomialLogisticRegression
impl Clone for MultinomialLogisticRegression
Source§fn clone(&self) -> MultinomialLogisticRegression
fn clone(&self) -> MultinomialLogisticRegression
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MultinomialLogisticRegression
impl RefUnwindSafe for MultinomialLogisticRegression
impl Send for MultinomialLogisticRegression
impl Sync for MultinomialLogisticRegression
impl Unpin for MultinomialLogisticRegression
impl UnsafeUnpin for MultinomialLogisticRegression
impl UnwindSafe for MultinomialLogisticRegression
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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