wnb


Namewnb JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/msamsami/weighted-naive-bayes
SummaryPython library for the implementations of general and weighted naive Bayes (WNB) classifiers.
upload_time2023-12-29 18:56:57
maintainer
docs_urlNone
authorMehdi Samsami
requires_python>=3.7
licenseBSD License
keywords python bayes naivebayes classifier probabilistic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # WNB: General and weighted naive Bayes classifiers

![](https://img.shields.io/badge/version-v0.2.1-green)
![](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)
![](https://github.com/msamsami/weighted-naive-bayes/actions/workflows/python-publish.yml/badge.svg)
[![](https://img.shields.io/pypi/v/wnb)](https://pypi.org/project/wnb/)
![](https://img.shields.io/pypi/dm/wnb)


<p>
<img src="https://raw.githubusercontent.com/msamsami/weighted-naive-bayes/main/docs/logo.png" alt="wnb logo" width="275" />
<br>
</p>

## Introduction
Naive 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 Bayes
The issue with the well-known implementations of the naive Bayes algorithm (such as the ones in `sklearn.naive_bayes`
module) 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 enters **WNB** library!
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 Bayes
Although 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. **WNB** library provides an efficient implementation
of gaussian MLD-WNB.

## Installation
The easiest way to install the wnb library is by using `pip`:
```
pip install wnb
```
This 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 started
Here, we show how you can use the library to train general and weighted naive Bayes classifiers. 

### General naive Bayes

A general naive Bayes model can be set up and used in four simple steps:

1. Import the `GeneralNB` class as well as `Distribution` enum class
```python
from wnb import GeneralNB, Distribution as D
```

2. Initialize a classifier and specify the likelihood distributions
```python
gnb = GeneralNB(distributions=[D.NORMAL, D.CATEGORICAL, D.EXPONENTIAL])
```

3. Fit the classifier to a training set (with three features)
```python
gnb.fit(X, y)
```

4. Predict on test data
```python
gnb.predict(X_test)
```

### Weighted naive Bayes

An MLD-WNB model can be set up and used in four simple steps:

1. Import the `GaussianWNB` class
```python
from wnb import GaussianWNB
```

2. Initialize a classifier
```python
wnb = GaussianWNB(max_iter=25, step_size=1e-2, penalty="l2")
```

3. Fit the classifier to a training set
```python
wnb.fit(X, y)
```

4. Predict on test data
```python
wnb.predict(x_test)
```

## Tests
To run the tests, install development requirements:
```
pip install -r requirements_dev.txt
```

Or, install the package with dev extras:
```
pip install wnb[dev]
```

Then, run pytest:
```
pytest
```

## Citation
If 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}},
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/msamsami/weighted-naive-bayes",
    "name": "wnb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "python,bayes,naivebayes,classifier,probabilistic",
    "author": "Mehdi Samsami",
    "author_email": "mehdisamsami@live.com",
    "download_url": "https://files.pythonhosted.org/packages/e3/35/d511170183b658019bd0b988b144c8e0a10803b0f2f655761d96fcd2eafa/wnb-0.2.1.tar.gz",
    "platform": null,
    "description": "# WNB: General and weighted naive Bayes classifiers\n\n![](https://img.shields.io/badge/version-v0.2.1-green)\n![](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)\n![](https://github.com/msamsami/weighted-naive-bayes/actions/workflows/python-publish.yml/badge.svg)\n[![](https://img.shields.io/pypi/v/wnb)](https://pypi.org/project/wnb/)\n![](https://img.shields.io/pypi/dm/wnb)\n\n\n<p>\n<img src=\"https://raw.githubusercontent.com/msamsami/weighted-naive-bayes/main/docs/logo.png\" alt=\"wnb logo\" width=\"275\" />\n<br>\n</p>\n\n## Introduction\nNaive Bayes is often recognized as one of the most popular classification algorithms in the machine learning community.\nThis package takes naive Bayes to a higher level by providing its implementations in more general and weighted settings.\n\n### General naive Bayes\nThe issue with the well-known implementations of the naive Bayes algorithm (such as the ones in `sklearn.naive_bayes`\nmodule) is that they assume a single distribution for the likelihoods of all features. Such an implementation can limit \nthose who need to develop naive Bayes models with different distributions for feature likelihood. And enters **WNB** library!\nIt allows you to customize your naive Bayes model by specifying the likelihood distribution of each feature separately.\nYou can choose from a range of continuous and discrete probability distributions to design your classifier.\n\n### Weighted naive Bayes\nAlthough naive Bayes has many advantages such as simplicity and interpretability, its conditional independence assumption\nrarely holds true in real-world applications. In order to alleviate its conditional independence assumption, many attribute\nweighting naive Bayes (WNB) approaches have been proposed. Most of the proposed methods involve computationally demanding\noptimization problems that do not allow for controlling the model's bias due to class imbalance. Minimum Log-likelihood\nDifference WNB (MLD-WNB) is a novel weighting approach that optimizes the weights according to the Bayes optimal decision\nrule and includes hyperparameters for controlling the model's bias. **WNB** library provides an efficient implementation\nof gaussian MLD-WNB.\n\n## Installation\nThe easiest way to install the wnb library is by using `pip`:\n```\npip install wnb\n```\nThis library is shipped as an all-in-one module implementation with minimalistic dependencies and requirements. \nFurthermore, it is fully compatible with Scikit-learn API.\n\n## Getting started\nHere, we show how you can use the library to train general and weighted naive Bayes classifiers. \n\n### General naive Bayes\n\nA general naive Bayes model can be set up and used in four simple steps:\n\n1. Import the `GeneralNB` class as well as `Distribution` enum class\n```python\nfrom wnb import GeneralNB, Distribution as D\n```\n\n2. Initialize a classifier and specify the likelihood distributions\n```python\ngnb = GeneralNB(distributions=[D.NORMAL, D.CATEGORICAL, D.EXPONENTIAL])\n```\n\n3. Fit the classifier to a training set (with three features)\n```python\ngnb.fit(X, y)\n```\n\n4. Predict on test data\n```python\ngnb.predict(X_test)\n```\n\n### Weighted naive Bayes\n\nAn MLD-WNB model can be set up and used in four simple steps:\n\n1. Import the `GaussianWNB` class\n```python\nfrom wnb import GaussianWNB\n```\n\n2. Initialize a classifier\n```python\nwnb = GaussianWNB(max_iter=25, step_size=1e-2, penalty=\"l2\")\n```\n\n3. Fit the classifier to a training set\n```python\nwnb.fit(X, y)\n```\n\n4. Predict on test data\n```python\nwnb.predict(x_test)\n```\n\n## Tests\nTo run the tests, install development requirements:\n```\npip install -r requirements_dev.txt\n```\n\nOr, install the package with dev extras:\n```\npip install wnb[dev]\n```\n\nThen, run pytest:\n```\npytest\n```\n\n## Citation\nIf you utilize this repository, please consider citing it with:\n\n```\n@misc{wnb,\n  author = {Mohammd Mehdi Samsami},\n  title = {WNB: General and weighted naive Bayes classifiers},\n  year = {2023},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://github.com/msamsami/weighted-naive-bayes}},\n}\n```\n",
    "bugtrack_url": null,
    "license": "BSD License",
    "summary": "Python library for the implementations of general and weighted naive Bayes (WNB) classifiers.",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/msamsami/weighted-naive-bayes"
    },
    "split_keywords": [
        "python",
        "bayes",
        "naivebayes",
        "classifier",
        "probabilistic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6c6901ec5ba6c5a7eed932c34cda35c730ff852234c842207a959148878bd0d7",
                "md5": "67fb730c321a3b1429fb1d4ae91b6db5",
                "sha256": "36d2cf599779cffc79f6e993e94d6397b347521d7f0d8f22fed3771246c6d0c1"
            },
            "downloads": -1,
            "filename": "wnb-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "67fb730c321a3b1429fb1d4ae91b6db5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 17069,
            "upload_time": "2023-12-29T18:56:55",
            "upload_time_iso_8601": "2023-12-29T18:56:55.425554Z",
            "url": "https://files.pythonhosted.org/packages/6c/69/01ec5ba6c5a7eed932c34cda35c730ff852234c842207a959148878bd0d7/wnb-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e335d511170183b658019bd0b988b144c8e0a10803b0f2f655761d96fcd2eafa",
                "md5": "cd226c46444a2746076a631a827e7abb",
                "sha256": "ee39ecdb2cec5d499ffcdb25b32408296c530d52d3f9c5d5afca4121806e8bdf"
            },
            "downloads": -1,
            "filename": "wnb-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "cd226c46444a2746076a631a827e7abb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 19714,
            "upload_time": "2023-12-29T18:56:57",
            "upload_time_iso_8601": "2023-12-29T18:56:57.750877Z",
            "url": "https://files.pythonhosted.org/packages/e3/35/d511170183b658019bd0b988b144c8e0a10803b0f2f655761d96fcd2eafa/wnb-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-29 18:56:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "msamsami",
    "github_project": "weighted-naive-bayes",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "wnb"
}
        
Elapsed time: 0.16927s