Skip to content

Commit

Permalink
update examples --> bump v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Aug 2, 2024
1 parent 3369fa1 commit ae5fb95
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 133 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
env/
build/
develop-eggs/
downloads/
#eggs/
#.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
#*.egg-info/
.installed.cfg
#*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# IDE settings
.vscode/
.Rproj.user
site/

# Apple files
.DS_Store

# R files
*.Rhistory

# Others
unifiedbooster-docs/
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright <2024> <T. Moudiki>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,91 @@
# unifiedbooster

![PyPI](https://img.shields.io/pypi/v/unifiedbooster) [![PyPI - License](https://img.shields.io/pypi/l/unifiedbooster)](https://github.com/thierrymoudiki/unifiedbooster/blob/master/LICENSE) [![Downloads](https://pepy.tech/badge/unifiedbooster)](https://pepy.tech/project/unifiedbooster)
[![Documentation](https://img.shields.io/badge/documentation-is_here-green)](https://techtonique.github.io/unifiedbooster/)

## Examples

### classification

```python
import unifiedbooster as ub
from sklearn.datasets import load_iris, load_breast_cancer, load_wine
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

datasets = [load_iris(), load_breast_cancer(), load_wine()]

for dataset in datasets:

X, y = dataset.data, dataset.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Initialize the unified regressor (example with XGBoost)
regressor1 = ub.GBDTClassifier(model_type='xgboost')
regressor2 = ub.GBDTClassifier(model_type='catboost')
regressor3 = ub.GBDTClassifier(model_type='lightgbm')

# Fit the model
regressor1.fit(X_train, y_train)
regressor2.fit(X_train, y_train)
regressor3.fit(X_train, y_train)

# Predict on the test set
y_pred1 = regressor1.predict(X_test)
y_pred2 = regressor2.predict(X_test)
y_pred3 = regressor3.predict(X_test)

# Evaluate the model
accuracy1 = accuracy_score(y_test, y_pred1)
accuracy2 = accuracy_score(y_test, y_pred2)
accuracy3 = accuracy_score(y_test, y_pred3)
print("-------------------------")
print(f"Classification Accuracy xgboost: {accuracy1:.2f}")
print(f"Classification Accuracy catboost: {accuracy2:.2f}")
print(f"Classification Accuracy lightgbm: {accuracy3:.2f}")
```

### regression

```python
import numpy as np
import unifiedbooster as ub
from sklearn.datasets import fetch_california_housing, load_diabetes
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error


datasets = [fetch_california_housing(), load_diabetes()]

for dataset in datasets:

# Load dataset
X, y = dataset.data, dataset.target

# Split dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Initialize the unified regressor (example with XGBoost)
regressor1 = ub.GBDTRegressor(model_type='xgboost')
regressor2 = ub.GBDTRegressor(model_type='catboost')
regressor3 = ub.GBDTRegressor(model_type='lightgbm')

# Fit the model
regressor1.fit(X_train, y_train)
regressor2.fit(X_train, y_train)
regressor3.fit(X_train, y_train)

# Predict on the test set
y_pred1 = regressor1.predict(X_test)
y_pred2 = regressor2.predict(X_test)
y_pred3 = regressor3.predict(X_test)

# Evaluate the model
mse1 = np.sqrt(mean_squared_error(y_test, y_pred1))
mse2 = np.sqrt(mean_squared_error(y_test, y_pred2))
mse3 = np.sqrt(mean_squared_error(y_test, y_pred3))
print("-------------------------")
print(f"Regression Root Mean Squared Error xgboost: {mse1:.2f}")
print(f"Regression Root Mean Squared Error catboost: {mse2:.2f}")
print(f"Regression Root Mean Squared Error lightgbm: {mse3:.2f}")
```
26 changes: 14 additions & 12 deletions examples/classification.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unifiedbooster as ub
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.metrics import accuracy_score

# Load dataset
Expand All @@ -10,25 +10,27 @@
# Split dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Initialize the unified regressor (example with XGBoost)
regressor1 = ub.GBDTClassifier(model_type='xgboost')
#regressor2 = ub.GBDTClassifier(model_type='catboost')
regressor3 = ub.GBDTClassifier(model_type='lightgbm')
# Initialize the unified clf (example with XGBoost)
clf1 = ub.GBDTClassifier(model_type='xgboost')
#clf2 = ub.GBDTClassifier(model_type='catboost')
clf3 = ub.GBDTClassifier(model_type='lightgbm')

# Fit the model
regressor1.fit(X_train, y_train)
#regressor2.fit(X_train, y_train)
regressor3.fit(X_train, y_train)
clf1.fit(X_train, y_train)
#clf2.fit(X_train, y_train)
clf3.fit(X_train, y_train)

# Predict on the test set
y_pred1 = regressor1.predict(X_test)
#y_pred2 = regressor2.predict(X_test)
y_pred3 = regressor3.predict(X_test)
y_pred1 = clf1.predict(X_test)
#y_pred2 = clf2.predict(X_test)
y_pred3 = clf3.predict(X_test)

# Evaluate the model
accuracy1 = accuracy_score(y_test, y_pred1)
#accuracy2 = accuracy_score(y_test, y_pred2)
accuracy3 = accuracy_score(y_test, y_pred3)
print(f"Classification Accuracy xgboost: {accuracy1:.2f}")
#print(f"Classification Accuracy catboost: {accuracy2:.2f}")
print(f"Classification Accuracy lightgbm: {accuracy3:.2f}")
print(f"Classification Accuracy lightgbm: {accuracy3:.2f}")
print(f"CV xgboost: {cross_val_score(clf1, X_train, y_train)}")
print(f"CV lightgbm: {cross_val_score(clf3, X_train, y_train)}")
24 changes: 13 additions & 11 deletions examples/regression.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unifiedbooster as ub
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.metrics import mean_squared_error

# Load dataset
Expand All @@ -10,20 +10,20 @@
# Split dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Initialize the unified regressor (example with XGBoost)
regressor1 = ub.GBDTRegressor(model_type='xgboost')
#regressor2 = ub.GBDTRegressor(model_type='catboost')
regressor3 = ub.GBDTRegressor(model_type='lightgbm')
# Initialize the unified regr (example with XGBoost)
regr1 = ub.GBDTregr(model_type='xgboost')
#regr2 = ub.GBDTregr(model_type='catboost')
regr3 = ub.GBDTregr(model_type='lightgbm')

# Fit the model
regressor1.fit(X_train, y_train)
#regressor2.fit(X_train, y_train)
regressor3.fit(X_train, y_train)
regr1.fit(X_train, y_train)
#regr2.fit(X_train, y_train)
regr3.fit(X_train, y_train)

# Predict on the test set
y_pred1 = regressor1.predict(X_test)
#y_pred2 = regressor2.predict(X_test)
y_pred3 = regressor3.predict(X_test)
y_pred1 = regr1.predict(X_test)
#y_pred2 = regr2.predict(X_test)
y_pred3 = regr3.predict(X_test)

# Evaluate the model
mse1 = mean_squared_error(y_test, y_pred1)
Expand All @@ -32,3 +32,5 @@
print(f"Regression Mean Squared Error xgboost: {mse1:.2f}")
#print(f"Regression Mean Squared Error catboost: {mse2:.2f}")
print(f"Regression Mean Squared Error lightgbm: {mse3:.2f}")
print(f"CV xgboost: {cross_val_score(regr1, X_train, y_train)}")
print(f"CV lightgbm: {cross_val_score(regr3, X_train, y_train)}")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

subprocess.check_call(['pip', 'install', 'Cython'])

__version__ = "0.2.1"
__version__ = "0.2.2"

here = path.abspath(path.dirname(__file__))

Expand Down
3 changes: 2 additions & 1 deletion unifiedbooster/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .gbdt import GBDT
from .gbdt_classification import GBDTClassifier
from .gbdt_regression import GBDTRegressor

__all__ = ["GBDTClassifier", "GBDTRegressor"]
__all__ = ["GBDT", "GBDTClassifier", "GBDTRegressor"]
Loading

0 comments on commit ae5fb95

Please sign in to comment.