Skip to content

Commit

Permalink
[Feature] Change study to a property (#5)
Browse files Browse the repository at this point in the history
Change `optuna.Study` to property
  • Loading branch information
chulhongsung authored Jul 19, 2024
1 parent bf15adf commit 5bbe58d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mqboost/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 getattr(self, "_study", None)

0 comments on commit 5bbe58d

Please sign in to comment.