Skip to content

Commit

Permalink
Merge pull request #35 from Techtonique/lsboost-lilbro
Browse files Browse the repository at this point in the history
Lsboost lilbro
  • Loading branch information
thierrymoudiki authored Oct 5, 2024
2 parents 9817a17 + ce70678 commit e454328
Show file tree
Hide file tree
Showing 53 changed files with 18,786 additions and 9,627 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ clean-build: ## remove build artifacts
rm -fr build/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.so' -exec rm -f {} +
find . -name '*.c' -exec rm -f {} +

clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
Expand Down Expand Up @@ -89,7 +91,10 @@ dist: clean ## builds source and wheel package
ls -l dist

install: clean ## install the package to the active Python's site-packages
python3 -m pip install .
python3 -m pip install . --verbose

run-examples: ## run all examples with one command
find examples -maxdepth 2 -name "*.py" -exec python3 {} \;
find examples -maxdepth 2 -name "*.py" -exec python3 {} \;

run-lazy: ## run all lazy estimators examples with one command
find examples -maxdepth 2 -name "*lazy*.py" -exec python3 {} \;
204 changes: 204 additions & 0 deletions examples/genboost_classifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import numpy as np
from sklearn.datasets import load_digits, load_breast_cancer, load_wine, load_iris
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score
from sklearn.tree import DecisionTreeRegressor
from sklearn.kernel_ridge import KernelRidge
from time import time
from os import chdir
from sklearn import metrics
import os

print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")

print(os.path.relpath(os.path.dirname(__file__)))

#wd="/workspace/mlsauce/mlsauce/examples"
#
#chdir(wd)

import mlsauce as ms

#ridge

print("\n")
print("GenericBoosting Decision tree -----")
print("\n")

print("\n")
print("breast_cancer data -----")

# data 1
breast_cancer = load_breast_cancer()
X = breast_cancer.data
y = breast_cancer.target
# split data into training test and test set
np.random.seed(15029)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2)

clf = DecisionTreeRegressor()
clf2 = KernelRidge()

obj = ms.GenericBoostingClassifier(clf, tolerance=1e-2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])

obj = ms.GenericBoostingClassifier(clf, tolerance=1e-2, n_clusters=2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])


# data 2
print("\n")
print("wine data -----")

wine = load_wine()
Z = wine.data
t = wine.target
np.random.seed(879423)
X_train, X_test, y_train, y_test = train_test_split(Z, t,
test_size=0.2)

obj = ms.GenericBoostingClassifier(clf)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])

obj = ms.GenericBoostingClassifier(clf, n_clusters=3)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])

# data 3
print("\n")
print("iris data -----")

iris = load_iris()
Z = iris.data
t = iris.target
np.random.seed(734563)
X_train, X_test, y_train, y_test = train_test_split(Z, t,
test_size=0.2)


obj = ms.GenericBoostingClassifier(clf)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])


print("\n")
print("GenericBoosting KRR -----")
print("\n")

obj = ms.GenericBoostingClassifier(clf2, tolerance=1e-2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])

obj = ms.GenericBoostingClassifier(clf2, tolerance=1e-2, n_clusters=2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])


# data 2
print("\n")
print("wine data -----")

wine = load_wine()
Z = wine.data
t = wine.target
np.random.seed(879423)
X_train, X_test, y_train, y_test = train_test_split(Z, t,
test_size=0.2)

obj = ms.GenericBoostingClassifier(clf2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])

obj = ms.GenericBoostingClassifier(clf2, n_clusters=3)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])

# data 3
print("\n")
print("iris data -----")

iris = load_iris()
Z = iris.data
t = iris.target
np.random.seed(734563)
X_train, X_test, y_train, y_test = train_test_split(Z, t,
test_size=0.2)


obj = ms.GenericBoostingClassifier(clf2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(obj.score(X_test, y_test))
print(time()-start)

print(obj.obj['loss'])

54 changes: 54 additions & 0 deletions examples/genboost_regressor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import subprocess
import sys
import os

print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")


subprocess.check_call([sys.executable, "-m", "pip", "install", "matplotlib"])

import mlsauce as ms
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score
from sklearn.tree import DecisionTreeRegressor
from time import time
from os import chdir
from sklearn import metrics


print("\n")
print("diabetes data -----")

regr = DecisionTreeRegressor()

diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target
# split data into training test and test set
np.random.seed(15029)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2)

obj = ms.GenericBoostingRegressor(regr, col_sample=0.9, row_sample=0.9)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(np.sqrt(np.mean(np.square(obj.predict(X_test) - y_test))))
print(time()-start)

print(obj.obj['loss'])

obj = ms.GenericBoostingRegressor(regr, col_sample=0.9, row_sample=0.9, n_clusters=2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(np.sqrt(np.mean(np.square(obj.predict(X_test) - y_test))))
print(time()-start)

print(obj.obj['loss'])
29 changes: 29 additions & 0 deletions examples/lazy_booster_classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import mlsauce as ms
from sklearn.datasets import load_breast_cancer, load_iris, load_wine, load_digits
from sklearn.model_selection import train_test_split
from time import time

print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")

#load_models = [load_breast_cancer, load_iris, load_wine, load_digits]
load_models = [load_breast_cancer, load_iris, load_wine]
#load_models = [load_breast_cancer]

for model in load_models:

data = model()
X = data.data
y= data.target

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .2, random_state = 13)

clf = ms.LazyBoostingClassifier(verbose=1, ignore_warnings=False,
custom_metric=None, preprocess=False)

start = time()
models, predictioms = clf.fit(X_train, X_test, y_train, y_test)
print(f"\nElapsed: {time() - start} seconds\n")

print(models)

17 changes: 17 additions & 0 deletions examples/lazy_booster_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import mlsauce as ms
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split

print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")

data = load_diabetes()
X = data.data
y= data.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .2, random_state = 123)

regr = ms.LazyBoostingRegressor(verbose=0, ignore_warnings=True,
custom_metric=None, preprocess=True)
models, predictioms = regr.fit(X_train, X_test, y_train, y_test)
model_dictionary = regr.provide_models(X_train, X_test, y_train, y_test)
print(models)
Loading

0 comments on commit e454328

Please sign in to comment.