Package: wnb
WNB: General and weighted naive Bayes classifiersIntroductionNaive Bayes is often recognized as one of the most popular classification algorithms in the machine learning community.
This package takes naive Bayes to a higher level by providing its implementations in more general and weighted settings.General naive BayesThe issue with the well-known implementations of the naive Bayes algorithm (such as the ones insklearn.naive_bayesmodule) is that they assume a single distribution for the likelihoods of all features. Such an implementation can limit
those who need to develop naive Bayes models with different distributions for feature likelihood. And entersWNBlibrary!
It allows you to customize your naive Bayes model by specifying the likelihood distribution of each feature separately.
You can choose from a range of continuous and discrete probability distributions to design your classifier.Weighted naive BayesAlthough naive Bayes has many advantages such as simplicity and interpretability, its conditional independence assumption
rarely holds true in real-world applications. In order to alleviate its conditional independence assumption, many attribute
weighting naive Bayes (WNB) approaches have been proposed. Most of the proposed methods involve computationally demanding
optimization problems that do not allow for controlling the model's bias due to class imbalance. Minimum Log-likelihood
Difference WNB (MLD-WNB) is a novel weighting approach that optimizes the weights according to the Bayes optimal decision
rule and includes hyperparameters for controlling the model's bias.WNBlibrary provides an efficient implementation
of gaussian MLD-WNB.InstallationThe easiest way to install the wnb library is by usingpip:pip install wnbThis library is shipped as an all-in-one module implementation with minimalistic dependencies and requirements.
Furthermore, it is fully compatible with Scikit-learn API.Getting startedHere, we show how you can use the library to train general and weighted naive Bayes classifiers.General naive BayesA general naive Bayes model can be set up and used in four simple steps:Import theGeneralNBclass as well asDistributionenum classfromwnbimportGeneralNB,DistributionasDInitialize a classifier and specify the likelihood distributionsgnb=GeneralNB(distributions=[D.NORMAL,D.CATEGORICAL,D.EXPONENTIAL])Fit the classifier to a training set (with three features)gnb.fit(X,y)Predict on test datagnb.predict(X_test)Weighted naive BayesAn MLD-WNB model can be set up and used in four simple steps:Import theGaussianWNBclassfromwnbimportGaussianWNBInitialize a classifierwnb=GaussianWNB(max_iter=25,step_size=1e-2,penalty="l2")Fit the classifier to a training setwnb.fit(X,y)Predict on test datawnb.predict(x_test)TestsTo run the tests, install development requirements:pip install -r requirements_dev.txtOr, install the package with dev extras:pip install wnb[dev]Then, run pytest:pytestCitationIf you utilize this repository, please consider citing it with:@misc{wnb,
  author = {Mohammd Mehdi Samsami},
  title = {WNB: General and weighted naive Bayes classifiers},
  year = {2023},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/msamsami/weighted-naive-bayes}},
}