From 840e16450f6fcd98a714030007fb4e9d9a635464 Mon Sep 17 00:00:00 2001 From: Sungchul Hong Date: Fri, 19 Jul 2024 14:45:36 +0900 Subject: [PATCH 1/7] add study method --- mqboost/engine.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mqboost/engine.py b/mqboost/engine.py index a9e69f4..8aa6070 100644 --- a/mqboost/engine.py +++ b/mqboost/engine.py @@ -207,13 +207,13 @@ def _study_func(trial: optuna.Trial) -> float: get_params_func=get_params_func, ) - study = optuna.create_study( + self._study = optuna.create_study( study_name=f"MQBoost_{self._model}", direction="minimize", load_if_exists=True, ) - study.optimize(_study_func, n_trials=n_trials) - return study.best_params + self._study.optimize(_study_func, n_trials=n_trials) + return self._study.best_params def __optuna_objective( self, @@ -282,3 +282,7 @@ def __is_xgb(self) -> bool: def __is_fitted(self) -> None: if not getattr(self, "_fitted", False): raise FittingException("train must be executed before predict") + + @property + def study(self) -> optuna.Study: + return self._study \ No newline at end of file From df75096d109db0e61e6acc51dcd1c338faa5258a Mon Sep 17 00:00:00 2001 From: Sungchul Hong Date: Fri, 19 Jul 2024 15:26:06 +0900 Subject: [PATCH 2/7] [Feature] Add study method --- mqboost/engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mqboost/engine.py b/mqboost/engine.py index 8aa6070..ce34384 100644 --- a/mqboost/engine.py +++ b/mqboost/engine.py @@ -285,4 +285,4 @@ def __is_fitted(self) -> None: @property def study(self) -> optuna.Study: - return self._study \ No newline at end of file + return self._study From d2f211f94932c89fbe16e8248018690bf8452980 Mon Sep 17 00:00:00 2001 From: Sungchul Hong Date: Fri, 19 Jul 2024 14:30:50 +0900 Subject: [PATCH 3/7] [Feature] Add study method --- mqboost/engine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mqboost/engine.py b/mqboost/engine.py index ce34384..b990a76 100644 --- a/mqboost/engine.py +++ b/mqboost/engine.py @@ -74,7 +74,7 @@ def __init__( ) self.x_train, self.y_train = prepare_train(x=x, y=y, alphas=self._alphas) self.dataset = self._train_dtype(data=self.x_train, label=self.y_train) - + def train( self, params: Optional[Dict[str, Any]] = None, @@ -282,7 +282,7 @@ def __is_xgb(self) -> bool: def __is_fitted(self) -> None: if not getattr(self, "_fitted", False): raise FittingException("train must be executed before predict") - + @property def study(self) -> optuna.Study: return self._study From 76308508384d49143af6ca2b77c6fc9ccbee7f39 Mon Sep 17 00:00:00 2001 From: Sungchul Hong Date: Fri, 19 Jul 2024 15:51:56 +0900 Subject: [PATCH 4/7] [Feature] Add study method --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4859c70..ecf0936 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,6 +7,6 @@ repos: - id: check-yaml - id: check-json - repo: https://github.com/psf/black - rev: stable + rev: 24.4.2 hooks: - id: black From c237fd2ed510e1a250e20ce1a61357fc29455685 Mon Sep 17 00:00:00 2001 From: Sungchul Hong Date: Fri, 19 Jul 2024 16:09:04 +0900 Subject: [PATCH 5/7] [Feature] Change study to a property --- .pre-commit-config.yaml | 2 +- mqboost/engine.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ecf0936..4859c70 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,6 +7,6 @@ repos: - id: check-yaml - id: check-json - repo: https://github.com/psf/black - rev: 24.4.2 + rev: stable hooks: - id: black diff --git a/mqboost/engine.py b/mqboost/engine.py index b990a76..ce34384 100644 --- a/mqboost/engine.py +++ b/mqboost/engine.py @@ -74,7 +74,7 @@ def __init__( ) self.x_train, self.y_train = prepare_train(x=x, y=y, alphas=self._alphas) self.dataset = self._train_dtype(data=self.x_train, label=self.y_train) - + def train( self, params: Optional[Dict[str, Any]] = None, @@ -282,7 +282,7 @@ def __is_xgb(self) -> bool: def __is_fitted(self) -> None: if not getattr(self, "_fitted", False): raise FittingException("train must be executed before predict") - + @property def study(self) -> optuna.Study: return self._study From 0eac0f3cdb634f98f857a8860ed3dd648159a478 Mon Sep 17 00:00:00 2001 From: Sungchul Hong Date: Fri, 19 Jul 2024 16:24:07 +0900 Subject: [PATCH 6/7] [Feature] Change study to a property --- mqboost/engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mqboost/engine.py b/mqboost/engine.py index ce34384..a374f77 100644 --- a/mqboost/engine.py +++ b/mqboost/engine.py @@ -285,4 +285,4 @@ def __is_fitted(self) -> None: @property def study(self) -> optuna.Study: - return self._study + return getattr(self, "study", None) From 753d540bd4f69e7c699541afc9dc81e4bb1acf4c Mon Sep 17 00:00:00 2001 From: Sungchul Hong Date: Fri, 19 Jul 2024 16:26:26 +0900 Subject: [PATCH 7/7] [Feature] Change study to a property --- mqboost/engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mqboost/engine.py b/mqboost/engine.py index a374f77..dfd7c49 100644 --- a/mqboost/engine.py +++ b/mqboost/engine.py @@ -285,4 +285,4 @@ def __is_fitted(self) -> None: @property def study(self) -> optuna.Study: - return getattr(self, "study", None) + return getattr(self, "_study", None)