Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI #185

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Collaborator Author

@nabenabe0928 nabenabe0928 Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading