Skip to main content

FittedComplementNB

Struct FittedComplementNB 

Source
pub struct FittedComplementNB<F> { /* private fields */ }
Expand description

Fitted Complement Naive Bayes classifier.

Implementations§

Source§

impl<F: Float + Send + Sync + 'static> FittedComplementNB<F>

Source

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
Source

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.

Source

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.

Source

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.

Source

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>

Source

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

Source

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

Source

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.

Source

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

Source

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>

Source§

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]

The sorted class labels — the classes_ attribute.
Source§

fn nb_predict(&self, x: &Array2<F>) -> Result<Array1<usize>, FerroError>

Predict class labels: classes_[argmax(jll, axis=1)]. Read more
Source§

fn nb_predict_log_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>

Return log-probability estimates: jll - logsumexp(jll, axis=1). Read more
Source§

fn nb_predict_proba(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>

Return probability estimates: exp(predict_log_proba). Read more
Source§

fn nb_predict_joint_log_proba( &self, x: &Array2<F>, ) -> Result<Array2<F>, FerroError>

Return the unnormalized joint log-probability estimates. Read more
Source§

impl<F: Clone> Clone for FittedComplementNB<F>

Source§

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

Source§

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

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

impl<F: Float + Send + Sync + 'static> HasClasses for FittedComplementNB<F>

Source§

fn classes(&self) -> &[usize]

Returns the sorted list of unique class labels.
Source§

fn n_classes(&self) -> usize

Returns the number of distinct classes.
Source§

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>

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

The prediction output type (e.g., ndarray::Array1<F> or ndarray::Array1<usize>).
Source§

type Error = FerroError

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

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