Skip to content

Commit

Permalink
Merge pull request #50 from msamsami/make-distribution-non-kw-arg
Browse files Browse the repository at this point in the history
fix: make `distributions` param positional-or-keyword in `GeneralNB`
  • Loading branch information
msamsami authored Feb 13, 2025
2 parents 1bb8693 + 29b1078 commit 9d028a6
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 103 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div align="center">

![Lastest Release](https://img.shields.io/badge/release-v0.7.0-green)
![Lastest Release](https://img.shields.io/badge/release-v0.8.0-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%20%7C%203.13-blue)<br>
![GitHub Workflow Status (build)](https://github.com/msamsami/wnb/actions/workflows/build.yml/badge.svg)
Expand Down Expand Up @@ -57,12 +57,12 @@ from wnb import GeneralNB, Distribution as D

2. Initialize a classifier with likelihood distributions specified
```python
gnb = GeneralNB(distributions=[D.NORMAL, D.CATEGORICAL, D.EXPONENTIAL, D.EXPONENTIAL])
clf = GeneralNB([D.NORMAL, D.CATEGORICAL, D.EXPONENTIAL, D.EXPONENTIAL])
```
or
```python
# Columns not explicitly specified will default to Gaussian (normal) distribution
gnb = GeneralNB(
clf = GeneralNB(
distributions=[
(D.CATEGORICAL, [1]),
(D.EXPONENTIAL, ["col3", "col4"]),
Expand All @@ -72,12 +72,12 @@ gnb = GeneralNB(

3. Fit the classifier to a training set (with four features)
```python
gnb.fit(X_train, y_train)
clf.fit(X_train, y_train)
```

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

### Weighted naive Bayes
Expand All @@ -91,17 +91,17 @@ from wnb import GaussianWNB

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

3. Fit the classifier to a training set
```python
gwnb.fit(X_train, y_train)
clf.fit(X_train, y_train)
```

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

## Compatibility with Scikit-learn 🤝
Expand Down
6 changes: 3 additions & 3 deletions examples/gnb_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

# Train and score sklearn GaussianNB classifier
# Train and score sklearn's GaussianNB classifier
gnb = GaussianNB()
gnb.fit(X_train, y_train)
print("sklearn | GaussianNB >> score >>", gnb.score(X_test, y_test))

# Train and score wnb GeneralNB classifier with Poisson likelihoods
gnb = GeneralNB(distributions=[D.POISSON] * X.shape[1])
# Train and score wnb's GeneralNB classifier with Poisson likelihoods
gnb = GeneralNB([D.POISSON] * X.shape[1])
gnb.fit(X_train, y_train)
print("wnb | GeneralNB >> score >>", gnb.score(X_test, y_test))
4 changes: 2 additions & 2 deletions examples/gnb_wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

# Train and score sklearn GaussianNB classifier
# Train and score sklearn's GaussianNB classifier
gnb = GaussianNB()
gnb.fit(X_train, y_train)
print("sklearn | GaussianNB >> score >>", gnb.score(X_test, y_test))

# Train and score wnb GeneralNB classifier with Log-normal likelihoods
# Train and score wnb's GeneralNB classifier with Log-normal likelihoods
gnb = GeneralNB(distributions=[(D.LOGNORMAL, range(X.shape[1]))])
gnb.fit(X_train, y_train)
print("wnb | GeneralNB >> score >>", gnb.score(X_test, y_test))
4 changes: 2 additions & 2 deletions examples/gwnb_breast_cancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=0)

# Train and score sklearn GaussianNB classifier
# Train and score sklearn's GaussianNB classifier
gnb = GaussianNB()
gnb.fit(X_train, y_train)
print("sklearn | GaussianNB >> score >>", gnb.score(X_test, y_test))

# Train and score wnb GaussianWNB classifier
# Train and score wnb's GaussianWNB classifier
gwnb = GaussianWNB(max_iter=20, step_size=0.01)
gwnb.fit(X_train, y_train)
print("wnb | GaussianWNB >> score >>", gwnb.score(X_test, y_test))
Loading

0 comments on commit 9d028a6

Please sign in to comment.