Skip to main content

GaussianNB

Gaussian Naive Bayes: each feature is modelled as class-conditional Gaussian, and predictions combine the per-feature likelihoods with the class priors under the naive independence assumption.

Algorithm

For each class the per-feature mean and variance are estimated by maximum likelihood (a small var_smoothing floor is added for stability). Posterior class scores are the sum of Gaussian log-likelihoods plus the log prior. Supports streaming via partial_fit with Welford-style variance updates.

Constructor

Skigen::GaussianNB<Scalar> model(VectorType priors = {}, Scalar var_smoothing = 1e-9);

Parameters

ParameterDefaultDescription
priorsemptyClass priors; estimated from data if empty.
var_smoothing1e-9Variance floor as a fraction of the largest feature variance.

Methods

MethodDescription
fit(X, y)Estimate per-class means and variances.
partial_fit(X, y, classes)Incremental update.
predict(X)MAP class labels.
predict_proba(X)Normalised class posteriors.

Fitted Attributes

AccessorDescription
theta()Per-class feature means.
var()Per-class feature variances.
class_prior()Class prior probabilities.

Example

Skigen::GaussianNB<double> nb;
nb.fit(X, y);
auto proba = nb.predict_proba(X_test);
Verified against scikit-learn

This estimator is checked by the parity suite. See the generator tests/parity/generate_naive_bayes_reference.py and the reference fixtures in tests/parity/data/gaussian_nb/, exercised by tests/parity/parity_naive_bayes.cpp.

API Reference

For full signatures see the GaussianNB API Reference.