pub struct FittedComplementNB<F> { /* private fields */ }Expand description
Fitted Complement Naive Bayes classifier.
Implementations§
Source§impl<F: Float + Send + Sync + 'static> FittedComplementNB<F>
impl<F: Float + Send + Sync + 'static> FittedComplementNB<F>
Sourcepub fn partial_fit(
&mut self,
x: &Array2<F>,
y: &Array1<usize>,
) -> Result<(), FerroError>
pub fn partial_fit( &mut self, x: &Array2<F>, y: &Array1<usize>, ) -> Result<(), FerroError>
Incrementally update the model with new data.
Accumulates feature counts and class counts, then recomputes the complement weights.
§Errors
FerroError::ShapeMismatchifxandyhave different row counts or the number of features does not match the fitted model.FerroError::InvalidParameterif any feature value is negative.
Sourcepub fn predict_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
pub fn predict_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Predict class probabilities for the given feature matrix.
Returns shape (n_samples, n_classes) where each row sums to 1.
Delegates to BaseNB::nb_predict_proba — with ComplementNB’s
sklearn-parity sign, the joint log-likelihood is X @ weights.T
directly, so exp(jll - logsumexp(jll)) is the softmax of the
complement scores.
§Errors
Returns FerroError::ShapeMismatch if the number of features does
not match the fitted model.
Sourcepub fn predict_joint_log_proba(
&self,
x: &Array2<F>,
) -> Result<Array2<F>, FerroError>
pub fn predict_joint_log_proba( &self, x: &Array2<F>, ) -> Result<Array2<F>, FerroError>
Compute the joint log-likelihood scores using sklearn’s sign convention: argmax(jll) gives the predicted class.
Returns shape (n_samples, n_classes). With the sklearn-parity sign,
X @ weights.T IS the joint log-likelihood. Matches sklearn
ComplementNB._joint_log_likelihood. Delegates to
BaseNB::nb_predict_joint_log_proba.
§Errors
Returns FerroError::ShapeMismatch if the number of features does
not match the fitted model.
Sourcepub fn predict_log_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
pub fn predict_log_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Compute log of class probabilities (numerically stable).
Returns shape (n_samples, n_classes). Delegates to
BaseNB::nb_predict_log_proba.
§Errors
Returns FerroError::ShapeMismatch if the number of features does
not match the fitted model.
Sourcepub fn score(&self, x: &Array2<F>, y: &Array1<usize>) -> Result<F, FerroError>
pub fn score(&self, x: &Array2<F>, y: &Array1<usize>) -> Result<F, FerroError>
Mean accuracy on the given test data and labels.
Equivalent to sklearn’s ClassifierMixin.score.
§Errors
Returns FerroError::ShapeMismatch if x.nrows() != y.len() or
the feature count does not match the fitted model.
Source§impl<F: Float + Send + Sync + 'static> FittedComplementNB<F>
impl<F: Float + Send + Sync + 'static> FittedComplementNB<F>
Sourcepub fn feature_log_prob(&self) -> &Array2<F>
pub fn feature_log_prob(&self) -> &Array2<F>
Empirical complement weights (the negated smoothed complement-class
log-probabilities), shape (n_classes, n_features).
Mirrors sklearn ComplementNB.feature_log_prob_
(_update_feature_log_prob, naive_bayes.py:1042).
Sourcepub fn feature_count(&self) -> &Array2<F>
pub fn feature_count(&self) -> &Array2<F>
Number of samples encountered for each (class, feature) during fitting,
shape (n_classes, n_features).
Mirrors sklearn ComplementNB.feature_count_
(_count, naive_bayes.py:961).
Sourcepub fn class_count(&self) -> Array1<F>
pub fn class_count(&self) -> Array1<F>
Number of samples encountered for each class during fitting,
shape (n_classes,).
Mirrors sklearn ComplementNB.class_count_
(_count, naive_bayes.py:951). class_counts is stored as integer
counts; this casts each to F.
Sourcepub fn feature_all(&self) -> Array1<F>
pub fn feature_all(&self) -> Array1<F>
Number of samples encountered for each feature during fitting (the
per-feature total across all classes), shape (n_features,).
Derived (not stored) as feature_count_.sum(axis=0), mirroring sklearn
ComplementNB.feature_all_ (_count, feature_all_ = feature_count_.sum(axis=0), naive_bayes.py:1029).
Sourcepub fn class_log_prior(&self) -> Array1<F>
pub fn class_log_prior(&self) -> Array1<F>
Smoothed empirical log probability for each class, shape (n_classes,).
Derived (not stored) as log(class_count_) - log(class_count_.sum()),
mirroring sklearn’s EMPIRICAL class_log_prior_ under the default
fit_prior=True (_update_class_log_prior, naive_bayes.py:600).
ComplementNB stores the empirical class-prior derivation; this returns
the EMPIRICAL prior (matching sklearn’s class_log_prior_ value on any
fit). Note: ComplementNB only consults class_log_prior_ in the
single-class edge case (naive_bayes.py:1047-1048); it does not affect
multi-class predictions.
Trait Implementations§
Source§impl<F: Float + Send + Sync + 'static> BaseNB<F> for FittedComplementNB<F>
impl<F: Float + Send + Sync + 'static> BaseNB<F> for FittedComplementNB<F>
Source§fn joint_log_likelihood(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn joint_log_likelihood(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Compute the joint log-likelihood scores for each class — sklearn
ComplementNB._joint_log_likelihood.
Returns X @ feature_log_prob_.T (shape (n_samples, n_classes)).
With ferrolearn’s sklearn-parity sign for feature_log_prob_,
higher is better and argmax(scores, axis=1) predicts the class.
Source§fn nb_classes(&self) -> &[usize]
fn nb_classes(&self) -> &[usize]
classes_ attribute.Source§fn nb_predict(&self, x: &Array2<F>) -> Result<Array1<usize>, FerroError>
fn nb_predict(&self, x: &Array2<F>) -> Result<Array1<usize>, FerroError>
classes_[argmax(jll, axis=1)]. Read moreSource§fn nb_predict_log_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn nb_predict_log_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
jll - logsumexp(jll, axis=1). Read moreSource§fn nb_predict_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn nb_predict_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
exp(predict_log_proba). Read moreSource§fn nb_predict_joint_log_proba(
&self,
x: &Array2<F>,
) -> Result<Array2<F>, FerroError>
fn nb_predict_joint_log_proba( &self, x: &Array2<F>, ) -> Result<Array2<F>, FerroError>
Source§impl<F: Clone> Clone for FittedComplementNB<F>
impl<F: Clone> Clone for FittedComplementNB<F>
Source§fn clone(&self) -> FittedComplementNB<F>
fn clone(&self) -> FittedComplementNB<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 FittedComplementNB<F>
impl<F: Debug> Debug for FittedComplementNB<F>
Source§impl<F: Float + Send + Sync + 'static> HasClasses for FittedComplementNB<F>
impl<F: Float + Send + Sync + 'static> HasClasses for FittedComplementNB<F>
Source§impl<F: Float + Send + Sync + 'static> Predict<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for FittedComplementNB<F>
impl<F: Float + Send + Sync + 'static> Predict<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for FittedComplementNB<F>
Source§fn predict(&self, x: &Array2<F>) -> Result<Array1<usize>, FerroError>
fn predict(&self, x: &Array2<F>) -> Result<Array1<usize>, FerroError>
Predict class labels for the given feature matrix.
With ComplementNB’s sklearn-parity sign, the highest joint
log-likelihood wins. Delegates to BaseNB::nb_predict.
§Errors
Returns FerroError::ShapeMismatch if the number of features does
not match the fitted model.
Source§type Output = ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>
type Output = ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>
ndarray::Array1<F> or ndarray::Array1<usize>).Source§type Error = FerroError
type Error = FerroError
predict.Auto Trait Implementations§
impl<F> Freeze for FittedComplementNB<F>where
F: Freeze,
impl<F> RefUnwindSafe for FittedComplementNB<F>where
F: RefUnwindSafe,
impl<F> Send for FittedComplementNB<F>where
F: Send,
impl<F> Sync for FittedComplementNB<F>where
F: Sync,
impl<F> Unpin for FittedComplementNB<F>where
F: Unpin,
impl<F> UnsafeUnpin for FittedComplementNB<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for FittedComplementNB<F>where
F: UnwindSafe + RefUnwindSafe,
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