Skip to content

CategoricalNB - #1985

Open
Shizoqua wants to merge 1 commit into
online-ml:mainfrom
Shizoqua:feat/1399-categorical-nb
Open

CategoricalNB#1985
Shizoqua wants to merge 1 commit into
online-ml:mainfrom
Shizoqua:feat/1399-categorical-nb

Conversation

@Shizoqua

Copy link
Copy Markdown

CategoricalNB

Fixes #1399

Summary

Adds naive_bayes.CategoricalNB, a Naive Bayes classifier for categorical features. For each class it keeps frequency counts of every value of every feature; prediction uses the joint log-likelihood with additive (Laplace) smoothing, matching sklearn.naive_bayes.CategoricalNB.

Features

  • learn_one / predict_one for online learning
  • learn_many / predict_many for mini-batch learning on any narwhals-supported eager dataframe (pandas, polars, pyarrow, ...)
  • Configurable alpha smoothing parameter
  • New estimator passes check_estimator

Tests

  • tests/naive_bayes/test_naive_bayes.py: learn_many vs learn_one equivalence, sparse input, sklearn equivalence, not-fitted behavior
  • Docstring example runs as a doctest
  • CodSpeed benchmark entries for learn and predict

Results match sklearn.naive_bayes.CategoricalNB on the same data.

Release note

  • docs/releases/unreleased.md: added under ## naive_bayes

Adds CategoricalNB, a Naive Bayes classifier for categorical features
that maintains per-class frequency counts for every value of every
feature and predicts with Laplace (additive) smoothing.

Supports both online mode (learn_one/predict_one) and mini-batch mode
(learn_many/predict_many) on any narwhals-supported eager dataframe,
mirroring sklearn's CategoricalNB. Results match
sklearn.naive_bayes.CategoricalNB.

Signed-off-by: Lanre Shittu <136805224+Shizoqua@users.noreply.github.com>
Signed-off-by: Shizoqua <136805224+Shizoqua@users.noreply.github.com>
@codspeed-hq

codspeed-hq Bot commented Aug 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks
⏩ 94 skipped benchmarks1


Comparing Shizoqua:feat/1399-categorical-nb (fcf65e0) with main (0b8596f)

Open in CodSpeed

Footnotes

  1. 94 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CategoricalNB

1 participant