Skip to content

Commit

Permalink
Merge pull request #185 from nabenabe0928/hotfix-ci
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
c-bata authored Dec 17, 2024
2 parents 4b12939 + 2a2af46 commit 05006b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
3 changes: 1 addition & 2 deletions optuna_integration/_lightgbm_tuner/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,7 @@ def sample_train_set(self) -> None:

def tune_feature_fraction(self, n_trials: int = 7) -> None:
param_name = "feature_fraction"
param_values = [0.4 + 0.6 * i / (n_trials - 1) for i in range(n_trials)]

param_values = cast(list, np.linspace(0.4, 1.0, n_trials).tolist())
sampler = optuna.samplers.GridSampler({param_name: param_values}, seed=self._optuna_seed)
self._tune_params([param_name], len(param_values), sampler, "feature_fraction")

Expand Down
31 changes: 20 additions & 11 deletions optuna_integration/sklearn/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def __call__(self, trial: Trial) -> float:
self._store_scores(trial, scores)

test_scores = scores["test_score"]
scores_list = test_scores if isinstance(test_scores, list) else [v for v in test_scores]
scores_list = test_scores if isinstance(test_scores, list) else list(test_scores.tolist())
try:
report_cross_validation_scores(trial, scores_list)
except ValueError as e:
Expand Down Expand Up @@ -303,12 +303,17 @@ def _cross_validate_with_pruning(

for step in range(self.max_iter):
for i, (train, test) in enumerate(self.cv.split(self.X, self.y, groups=self.groups)):
_out = self._partial_fit_and_score(estimators[i], train, test, partial_fit_params)
out = np.asarray(_out, dtype=np.float64)
out = list(
np.asarray(
self._partial_fit_and_score(
estimators[i], train, test, partial_fit_params
),
dtype=float,
).tolist()
)

if self.return_train_score:
scores["train_score"][i] = out[0]
out = out[1:]
scores["train_score"][i] = out.pop(0)

scores["test_score"][i] = out[0]
scores["fit_time"][i] += out[1]
Expand Down Expand Up @@ -636,17 +641,20 @@ def decision_function(

return self.best_estimator_.decision_function(X, **kwargs)

@property
def inverse_transform(self) -> Callable[..., TwoDimArrayLikeType]:
def inverse_transform(
self, X: TwoDimArrayLikeType, *args: Any, **kwargs: Any
) -> TwoDimArrayLikeType:
"""Call ``inverse_transform`` on the best estimator.
This is available only if the underlying estimator supports
``inverse_transform`` and ``refit`` is set to :obj:`True`.
Please check the following to know more about ``inverse_transform``:
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.FunctionTransformer.html#sklearn.preprocessing.FunctionTransformer.inverse_transform
"""

self._check_is_fitted()

return self.best_estimator_.inverse_transform
return self.best_estimator_.inverse_transform(X, *args, **kwargs)

def predict(
self, X: TwoDimArrayLikeType, **kwargs: Any
Expand Down Expand Up @@ -703,17 +711,18 @@ def set_user_attr(self) -> Callable[..., None]:

return self.study_.set_user_attr

@property
def transform(self) -> Callable[..., TwoDimArrayLikeType]:
def transform(self, X: TwoDimArrayLikeType, *args: Any, **kwargs: Any) -> TwoDimArrayLikeType:
"""Call ``transform`` on the best estimator.
This is available only if the underlying estimator supports
``transform`` and ``refit`` is set to :obj:`True`.
Please check the following to know more about ``transform``:
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.FunctionTransformer.html#sklearn.preprocessing.FunctionTransformer.transform
"""

self._check_is_fitted()

return self.best_estimator_.transform
return self.best_estimator_.transform(X, *args, **kwargs)

@property
def trials_dataframe(self) -> Callable[..., "pd.DataFrame"]:
Expand Down

0 comments on commit 05006b3

Please sign in to comment.