From 6f8e92dde29fca3c33bbcd572ff3f93bd1336a5f Mon Sep 17 00:00:00 2001 From: Thierry Moudiki Date: Sun, 6 Oct 2024 03:14:32 +0000 Subject: [PATCH] fix verbosity in Lazy* --- examples/lazy_booster_classification.py | 4 +- examples/lazy_booster_regression.py | 14 ++++++- mlsauce.egg-info/PKG-INFO | 2 +- mlsauce/lazybooster/config.py | 11 +++-- mlsauce/lazybooster/lazyboosterclassif.py | 42 +++++++++++++------- mlsauce/lazybooster/lazyboosterregression.py | 37 +++++++++-------- setup.py | 2 +- 7 files changed, 73 insertions(+), 39 deletions(-) diff --git a/examples/lazy_booster_classification.py b/examples/lazy_booster_classification.py index 7210568..3895f03 100644 --- a/examples/lazy_booster_classification.py +++ b/examples/lazy_booster_classification.py @@ -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: @@ -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() diff --git a/examples/lazy_booster_regression.py b/examples/lazy_booster_regression.py index 7edeec3..e918cf2 100644 --- a/examples/lazy_booster_regression.py +++ b/examples/lazy_booster_regression.py @@ -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") @@ -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) \ No newline at end of file +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) diff --git a/mlsauce.egg-info/PKG-INFO b/mlsauce.egg-info/PKG-INFO index b907eba..225645a 100644 --- a/mlsauce.egg-info/PKG-INFO +++ b/mlsauce.egg-info/PKG-INFO @@ -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: thierry.moudiki@gmail.com diff --git a/mlsauce/lazybooster/config.py b/mlsauce/lazybooster/config.py index 07ab90f..849efb9 100644 --- a/mlsauce/lazybooster/config.py +++ b/mlsauce/lazybooster/config.py @@ -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", ] diff --git a/mlsauce/lazybooster/lazyboosterclassif.py b/mlsauce/lazybooster/lazyboosterclassif.py index 842f050..abfdcf3 100644 --- a/mlsauce/lazybooster/lazyboosterclassif.py +++ b/mlsauce/lazybooster/lazyboosterclassif.py @@ -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) ``` """ @@ -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: @@ -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) diff --git a/mlsauce/lazybooster/lazyboosterregression.py b/mlsauce/lazybooster/lazyboosterregression.py index 8736c40..d803608 100644 --- a/mlsauce/lazybooster/lazyboosterregression.py +++ b/mlsauce/lazybooster/lazyboosterregression.py @@ -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) + ``` """ @@ -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) @@ -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...") diff --git a/setup.py b/setup.py index 2babd28..f050544 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ MAINTAINER_EMAIL = 'thierry.moudiki@gmail.com' LICENSE = 'BSD3 Clause Clear' -__version__ = '0.20.0' +__version__ = '0.20.1' VERSION = __version__