Skip to content

Commit

Permalink
Merge pull request #35 from msamsami/fix-maintain-precommit
Browse files Browse the repository at this point in the history
maint:pre-commit configs, script names, end of files, black version, README
  • Loading branch information
msamsami authored Aug 24, 2024
2 parents 3701e91 + 6010603 commit 2e17f79
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 47 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install build
pip install -r requirements.txt
pip install -r requirements_dev.txt
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install build
pip install -r requirements.txt
pip install -r requirements_dev.txt
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ dmypy.json
/test
test.ipynb
dummy.py
.DS_Store
.DS_Store
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ repos:
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include README.md
include LICENSE
recursive-include wnb *.py
recursive-include tests *.py
recursive-include tests *.py
48 changes: 35 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div align="center">
<img src="https://raw.githubusercontent.com/msamsami/weighted-naive-bayes/main/docs/logo.png" alt="wnb logo" width="275" />
<img src="https://raw.githubusercontent.com/msamsami/wnb/main/docs/logo.png" alt="wnb logo" width="275" />
</div>

<div align="center"> <b>General and weighted naive Bayes classifiers</b> </div>
<div align="center">Scikit-learn-compatible</div> <br>

<div align="center">

![Lastest Release](https://img.shields.io/badge/release-v0.2.6-green)
![Lastest Release](https://img.shields.io/badge/release-v0.2.7-green)
[![PyPI Version](https://img.shields.io/pypi/v/wnb)](https://pypi.org/project/wnb/)
![Python Versions](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)<br>
![GitHub Workflow Status (build)](https://github.com/msamsami/weighted-naive-bayes/actions/workflows/python-publish.yml/badge.svg)
![GitHub Workflow Status (build)](https://github.com/msamsami/wnb/actions/workflows/python-publish.yml/badge.svg)
![PyPI License](https://img.shields.io/pypi/l/wnb)
[![PyPi Downloads](https://static.pepy.tech/badge/wnb)](https://pepy.tech/project/wnb)

Expand All @@ -26,14 +26,35 @@ The issue with the well-known implementations of the naive Bayes algorithm (such
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`:
```
This library is shipped as an all-in-one module implementation with minimalistic dependencies and requirements. Furthermore, it fully **adheres to Scikit-learn API** ❤️.

### Prerequisites
Ensure that Python 3.8 or higher is installed on your machine before installing **WNB**.

### PyPi
```bash
pip install wnb
```
This library is shipped as an all-in-one module implementation with minimalistic dependencies and requirements. Furthermore, it fully **adheres to Scikit-learn API** ❤️.

### Poetry
```bash
poetry add wnb
```

### GitHub
```bash
# Clone the repository
git clone https://github.com/msamsami/wnb.git

# Navigate into the project directory
cd wnb

# Install the package
pip install .
```

## Getting started ⚡️
Here, we show how you can use the library to train general and weighted naive Bayes classifiers.
Here, we show how you can use the library to train general and weighted naive Bayes classifiers.

### General naive Bayes

Expand Down Expand Up @@ -114,13 +135,14 @@ These benchmarks highlight the potential of WNB classifiers to provide better pe
The benchmark scripts used to obtain these results can be found under _tests/benchmarks/_ directory.

## Tests
To run the tests, make sure to clone the repository and install the development requirements:
```
To run the tests, make sure to clone the repository and install the development requirements in addition to base requirements:
```bash
pip install -r requirements.txt
pip install -r requirements_dev.txt
```

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

Expand All @@ -129,7 +151,7 @@ You can support the project in the following ways:

⭐ Star WNB on GitHub (click the star button in the top right corner)

💡 Provide your feedback or propose ideas in the [Issues section](https://github.com/msamsami/weighted-naive-bayes/issues)
💡 Provide your feedback or propose ideas in the [Issues section](https://github.com/msamsami/wnb/issues)

📰 Post about WNB on LinkedIn or other platforms

Expand All @@ -144,6 +166,6 @@ If you utilize this repository, please consider citing it with:
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/msamsami/weighted-naive-bayes}},
howpublished = {\url{https://github.com/msamsami/wnb}},
}
```
```
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ dependencies = [
"typing-extensions>=4.8.0",
]

[project.urls]
Homepage = "https://github.com/msamsami/wnb"
Source = "https://github.com/msamsami/wnb"

[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"black>=24.4.2",
"black==24.8.0",
"tqdm>=4.65.0",
"pre-commit>=3.7.1",
"isort==5.13.2",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pandas>=1.4.1
numpy<2.0.0
scipy>=1.8.0
scikit-learn>=1.0.2
typing-extensions>=4.8.0
typing-extensions>=4.8.0
9 changes: 2 additions & 7 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
pandas>=1.4.1
numpy<2.0.0
scipy>=1.8.0
scikit-learn>=1.0.2
typing-extensions>=4.8.0
pytest>=7.0.0
black>=24.4.2
black==24.8.0
tqdm>=4.65.0
pre-commit>=3.7.1
isort==5.13.2
isort==5.13.2
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name = wnb
version = attr: wnb.__version__
author = Mehdi Samsami
author_email = [email protected]
url = https://github.com/msamsami/weighted-naive-bayes
url = https://github.com/msamsami/wnb
description = Python library for the implementations of general and weighted naive Bayes (WNB) classifiers.
long_description = file: README.md
long_description_content_type = text/markdown
license = BSD
license_file = LICENSE
keywords = python, bayes, naive bayes, classifier, probabilistic
classifiers =
classifiers =
Intended Audience :: Science/Research
Intended Audience :: Developers
Topic :: Scientific/Engineering
Expand Down Expand Up @@ -38,7 +38,7 @@ install_requires =
[options.extras_require]
dev =
pytest>=7.0.0
black>=24.4.2
black==24.8.0
tqdm>=4.65.0
pre-commit>=3.7.1
isort==5.13.2
Expand All @@ -47,5 +47,5 @@ dev =
test = pytest

[tool:pytest]
filterwarnings =
filterwarnings =
ignore
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
author="Mehdi Samsami",
author_email="[email protected]",
license="BSD License",
url="https://github.com/msamsami/weighted-naive-bayes",
url="https://github.com/msamsami/wnb",
long_description=codecs.open(
path.join(path.abspath(path.dirname(__file__)), "README.md"), encoding="utf-8"
).read(),
Expand Down Expand Up @@ -45,7 +45,7 @@
extras_require={
"dev": [
"pytest>=7.0.0",
"black>=24.4.2",
"black==24.8.0",
"tqdm>=4.65.0",
"pre-commit>=3.7.1",
"isort==5.13.2",
Expand Down
4 changes: 2 additions & 2 deletions wnb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Python library for the implementations of general and weighted naive Bayes (WNB) classifiers.
"""

__version__ = "0.2.6"
__version__ = "0.2.7"
__author__ = "Mehdi Samsami"


from ._base import ContinuousDistMixin, DiscreteDistMixin
from .base import ContinuousDistMixin, DiscreteDistMixin
from .enums import Distribution
from .gnb import GeneralNB
from .gwnb import GaussianWNB
Expand Down
2 changes: 1 addition & 1 deletion wnb/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas as pd
from scipy.sparse import spmatrix

from ._base import ContinuousDistMixin, DiscreteDistMixin
from .base import ContinuousDistMixin, DiscreteDistMixin
from .enums import Distribution

__all__ = ["MatrixLike", "ArrayLike", "Int", "Float", "DistibutionLike"]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion wnb/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from scipy.special import beta, gamma
from scipy.stats import chi2

from ._base import ContinuousDistMixin, DiscreteDistMixin
from .base import ContinuousDistMixin, DiscreteDistMixin
from .enums import Distribution as D

__all__ = [
Expand Down
6 changes: 2 additions & 4 deletions wnb/gnb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
from sklearn.utils.validation import check_is_fitted
from typing_extensions import Self

from ._base import DistMixin
from ._typing import ArrayLike, DistibutionLike, Float, MatrixLike
from .base import DistMixin
from .dist import NonNumericDistributions
from .enums import Distribution
from .utils import get_dist_class, is_dist_supported

__all__ = [
"GeneralNB",
]
__all__ = ["GeneralNB"]


class GeneralNB(ClassifierMixin, BaseEstimator, metaclass=ABCMeta):
Expand Down
4 changes: 1 addition & 3 deletions wnb/gwnb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

from ._typing import ArrayLike, Float, Int, MatrixLike

__all__ = [
"GaussianWNB",
]
__all__ = ["GaussianWNB"]


class GaussianWNB(ClassifierMixin, BaseEstimator, metaclass=ABCMeta):
Expand Down
9 changes: 4 additions & 5 deletions wnb/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import contextlib
from typing import Optional

from ._base import DistMixin
from ._typing import DistibutionLike
from .base import DistMixin
from .dist import AllDistributions
from .enums import Distribution

Expand All @@ -11,8 +11,7 @@

def is_dist_supported(dist: DistibutionLike) -> bool:
with contextlib.suppress(TypeError):
issubclass(dist, DistMixin)
return True
return issubclass(dist, DistMixin)

if (
isinstance(dist, Distribution)
Expand All @@ -26,8 +25,8 @@ def is_dist_supported(dist: DistibutionLike) -> bool:

def get_dist_class(name_or_type: DistibutionLike) -> Optional[DistMixin]:
with contextlib.suppress(TypeError):
issubclass(name_or_type, DistMixin)
return name_or_type
if issubclass(name_or_type, DistMixin):
return name_or_type

if isinstance(name_or_type, Distribution) or name_or_type in Distribution.__members__.values():
return AllDistributions[name_or_type]
Expand Down

0 comments on commit 2e17f79

Please sign in to comment.