Skip to content

Commit

Permalink
fix verbosity in Lazy*
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Oct 6, 2024
1 parent ce70678 commit 6f8e92d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 39 deletions.
4 changes: 2 additions & 2 deletions examples/lazy_booster_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#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]
#load_models = [load_digits]

for model in load_models:

Expand All @@ -18,7 +18,7 @@

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,
clf = ms.LazyBoostingClassifier(verbose=0, ignore_warnings=True,
custom_metric=None, preprocess=False)

start = time()
Expand Down
14 changes: 13 additions & 1 deletion examples/lazy_booster_regression.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import mlsauce as ms
from sklearn.datasets import load_diabetes
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split

print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
Expand All @@ -14,4 +15,15 @@
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)
print(models)

data = fetch_california_housing()
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)
2 changes: 1 addition & 1 deletion mlsauce.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: mlsauce
Version: 0.20.0
Version: 0.20.1
Summary: Miscellaneous Statistical/Machine Learning tools
Maintainer: T. Moudiki
Maintainer-email: [email protected]
Expand Down
11 changes: 8 additions & 3 deletions mlsauce/lazybooster/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
from sklearn.utils import all_estimators

removed_regressors = [
"AdaBoostRegressor",
"BaggingRegressor",
"TheilSenRegressor",
"ARDRegression",
"ExtraTreesRegressor",
"CCA",
"GaussianProcessRegressor",
"GradientBoostingRegressor",
"HistGradientBoostingRegressor",
"IsotonicRegression",
"KernelRidge",
"MLPRegressor",
#"KernelRidge",
"MultiOutputRegressor",
"MultiTaskElasticNet",
"MultiTaskElasticNetCV",
"MultiTaskLasso",
"MultiTaskLassoCV",
"NuSVR",
#"NuSVR",
"OrthogonalMatchingPursuit",
"OrthogonalMatchingPursuitCV",
"PLSCanonical",
"PLSRegression",
"RadiusNeighborsRegressor",
"RandomForestRegressor",
"RegressorChain",
"StackingRegressor",
"SVR",
#"SVR",
"VotingRegressor",
]

Expand Down
42 changes: 27 additions & 15 deletions mlsauce/lazybooster/lazyboosterclassif.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,30 @@ class LazyBoostingClassifier(ClassifierMixin):
Examples
```python
import mlsauce as ms
from sklearn.datasets import load_breast_cancer
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
data = load_breast_cancer()
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)
clf = ms.LazyBoostingClassifier(verbose=0, ignore_warnings=True, custom_metric=None)
models, predictions = clf.fit(X_train, X_test, y_train, y_test)
model_dictionary = clf.provide_models(X_train,X_test,y_train,y_test)
print(models)
from time import time
load_models = [load_breast_cancer, load_iris, load_wine]
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)
```
"""
Expand Down Expand Up @@ -351,12 +363,13 @@ def fit(self, X_train, X_test, y_train, y_test, **kwargs):
if "random_state" in model().get_params().keys():
fitted_clf = GenericBoostingClassifier(
{**other_args, **kwargs},
verbose=self.verbose,
obj=model(random_state=self.random_state),
)

else:
fitted_clf = GenericBoostingClassifier(
obj=model(**kwargs),
obj=model(**kwargs), verbose=self.verbose,
)

if self.verbose > 0:
Expand Down Expand Up @@ -433,12 +446,11 @@ def fit(self, X_train, X_test, y_train, y_test, **kwargs):
if "random_state" in model().get_params().keys():
fitted_clf = GenericBoostingClassifier(
obj=model(random_state=self.random_state),
**kwargs
)
verbose=self.verbose, **kwargs)

else:
fitted_clf = GenericBoostingClassifier(
obj=model(),
obj=model(), verbose=self.verbose,
**kwargs)

fitted_clf.fit(X_train, y_train)
Expand Down
37 changes: 21 additions & 16 deletions mlsauce/lazybooster/lazyboosterregression.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,23 @@ class LazyBoostingRegressor(RegressorMixin):
Examples:
```python
import os
import mlsauce as ms
import numpy as np
from sklearn import datasets
from sklearn.utils import shuffle
diabetes = datasets.load_diabetes()
X, y = shuffle(diabetes.data, diabetes.target, random_state=13)
X = X.astype(np.float32)
offset = int(X.shape[0] * 0.9)
X_train, y_train = X[:offset], y[:offset]
X_test, y_test = X[offset:], y[offset:]
reg = ns.LazyBoostingRegressor(verbose=0, ignore_warnings=False, custom_metric=None)
models, predictions = reg.fit(X_train, X_test, y_train, y_test)
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
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)
```
"""

Expand Down Expand Up @@ -327,7 +328,9 @@ def fit(self, X_train, X_test, y_train, y_test, **kwargs):

try:

model = GenericBoostingRegressor(obj=regr(), **kwargs)
model = GenericBoostingRegressor(obj=regr(),
verbose=self.verbose,
**kwargs)

model.fit(X_train, y_train)

Expand Down Expand Up @@ -389,7 +392,9 @@ def fit(self, X_train, X_test, y_train, y_test, **kwargs):
start = time.time()
try:

model = GenericBoostingRegressor(obj=regr(), **kwargs)
model = GenericBoostingRegressor(obj=regr(),
verbose=self.verbose,
**kwargs)

if self.verbose > 0:
print("\n Fitting boosted " + name + " model...")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
MAINTAINER_EMAIL = '[email protected]'
LICENSE = 'BSD3 Clause Clear'

__version__ = '0.20.0'
__version__ = '0.20.1'

VERSION = __version__

Expand Down

0 comments on commit 6f8e92d

Please sign in to comment.