Skip to content

Commit 1990929

Browse files
authored
Loosen scikit-learn version (#297)
1 parent ab5f89d commit 1990929

File tree

6 files changed

+14
-23
lines changed

6 files changed

+14
-23
lines changed

ads/hpo/ads_search_space.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __init__(self, strategy):
121121
def suggest_space(self, **kwargs):
122122
space = {
123123
"alpha": LogUniformDistribution(10**-4, 10**-1),
124-
"penalty": CategoricalDistribution(["l1", "l2", "none"]),
124+
"penalty": CategoricalDistribution(["l1", "l2", None]),
125125
}
126126
if self.strategy != "perfunctory":
127127
space.update(
@@ -144,7 +144,6 @@ def __init__(self, strategy):
144144
super(SVCSearchSpace, self).__init__(strategy)
145145

146146
def suggest_space(self, **kwargs):
147-
148147
space = {
149148
"C": LogUniformDistribution(10**-4, 10**-1),
150149
"max_iter": CategoricalDistribution([1000]),
@@ -172,7 +171,6 @@ def __init__(self, strategy):
172171
super(LinearSVCSearchSpace, self).__init__(strategy)
173172

174173
def suggest_space(self, **kwargs):
175-
176174
space = {
177175
"C": LogUniformDistribution(10**-4, 10**-1),
178176
"dual": CategoricalDistribution([False]),
@@ -197,7 +195,6 @@ def __init__(self, strategy):
197195
super(LinearSVRSearchSpace, self).__init__(strategy)
198196

199197
def suggest_space(self, **kwargs):
200-
201198
space = {"C": LogUniformDistribution(10**-4, 10**-1)}
202199

203200
if self.strategy != "perfunctory":
@@ -217,7 +214,6 @@ def __init__(self, strategy):
217214
super(DecisionTreeClassifierSearchSpace, self).__init__(strategy)
218215

219216
def suggest_space(self, **kwargs):
220-
221217
space = {
222218
"max_depth": IntUniformDistribution(1, 5),
223219
"min_impurity_decrease": UniformDistribution(0, 0.05),
@@ -241,7 +237,6 @@ def __init__(self, strategy):
241237
super(DecisionTreeRegressorSearchSpace, self).__init__(strategy)
242238

243239
def suggest_space(self, **kwargs):
244-
245240
space = {
246241
"max_depth": IntUniformDistribution(1, 5),
247242
"min_impurity_decrease": UniformDistribution(0, 0.05),
@@ -252,7 +247,11 @@ def suggest_space(self, **kwargs):
252247
space.update(
253248
{
254249
"criterion": CategoricalDistribution(
255-
["mse", "friedman_mse", "mae"]
250+
[
251+
"squared_error",
252+
"friedman_mse",
253+
"absolute_error",
254+
]
256255
),
257256
"min_samples_leaf": IntUniformDistribution(2, 500),
258257
}
@@ -335,7 +334,6 @@ def __init__(self, strategy):
335334
super(ExtraTreesClassifierSearchSpace, self).__init__(strategy)
336335

337336
def suggest_space(self, **kwargs):
338-
339337
space = {
340338
"n_estimators": IntUniformDistribution(50, 250),
341339
"max_depth": IntUniformDistribution(1, 5),
@@ -374,7 +372,6 @@ def __init__(self, strategy):
374372
super(GradientBoostingRegressorSearchSpace, self).__init__(strategy)
375373

376374
def suggest_space(self, **kwargs):
377-
378375
space = {
379376
"max_depth": IntUniformDistribution(1, 5),
380377
"max_features": CategoricalDistribution(["sqrt", "log2"]),

ads/hpo/objective.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ def _cross_validate_with_pruning(
184184

185185
for step in range(self.max_iter):
186186
for i, (train, test) in enumerate(self.cv.split(X, y, groups=self.groups)):
187-
188187
out = self._partial_fit_and_score(
189188
X, y, estimators[i], train, test, partial_fit_params
190189
)
@@ -201,7 +200,6 @@ def _cross_validate_with_pruning(
201200
trial.report(intermediate_value, step=step)
202201

203202
if trial.should_prune():
204-
205203
self._store_scores(trial, scores, self.scoring_name)
206204

207205
raise optuna.TrialPruned(f"trial was pruned at iteration {step}.")

ads/hpo/search_cv.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class State(Enum):
6767
COMPLETED = auto()
6868

6969

70-
class InvalidStateTransition(Exception): # pragma: no cover
70+
class InvalidStateTransition(Exception): # pragma: no cover
7171
"""
7272
`Invalid State Transition` is raised when an invalid transition request is made, such as calling
7373
halt without a running process.
@@ -76,7 +76,7 @@ class InvalidStateTransition(Exception): # pragma: no cover
7676
pass
7777

7878

79-
class ExitCriterionError(Exception): # pragma: no cover
79+
class ExitCriterionError(Exception): # pragma: no cover
8080
"""
8181
`ExitCriterionError` is raised when an attempt is made to check exit status for a different exit
8282
type than the tuner was initialized with. For example, if an HPO study has an exit criteria based
@@ -87,14 +87,14 @@ class ExitCriterionError(Exception): # pragma: no cover
8787
pass
8888

8989

90-
class DuplicatedStudyError(Exception): # pragma: no cover
90+
class DuplicatedStudyError(Exception): # pragma: no cover
9191
"""
9292
`DuplicatedStudyError` is raised when a new tuner process is created with a study name that
9393
already exists in storage.
9494
"""
9595

9696

97-
class NoRestartError(Exception): # pragma: no cover
97+
class NoRestartError(Exception): # pragma: no cover
9898
"""
9999
`NoRestartError` is raised when an attempt is made to check how many seconds have transpired since
100100
the HPO process was last resumed from a halt. This can happen if the process has been terminated
@@ -497,7 +497,6 @@ def _get_param_distributions(self, strategy):
497497
return param_distributions
498498

499499
def _check_search_space(self, param_distributions):
500-
501500
validate_search_space(self.model.get_params().keys(), param_distributions)
502501

503502
def _check_is_fitted(self):
@@ -1044,7 +1043,7 @@ def _extract_estimator(self):
10441043
def _extract_scoring_name(self):
10451044
if isinstance(self.scoring, str):
10461045
return self.scoring
1047-
if self._scorer.__class__.__name__ != "function":
1046+
if not callable(self._scorer):
10481047
return (
10491048
self._scorer
10501049
if isinstance(self._scorer, str)

ads/type_discovery/typed_feature.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def sub_vectorization(
349349
unigrams = {
350350
k: int(v)
351351
for k, v in dict(
352-
zip(v1.get_feature_names(), np.asarray(X1.sum(axis=0)).ravel())
352+
zip(v1.get_feature_names_out(), np.asarray(X1.sum(axis=0)).ravel())
353353
).items()
354354
}
355355

@@ -366,7 +366,7 @@ def sub_vectorization(
366366
bigrams = {
367367
k: int(v)
368368
for k, v in dict(
369-
zip(v2.get_feature_names(), np.asarray(X2.sum(axis=0)).ravel())
369+
zip(v2.get_feature_names_out(), np.asarray(X2.sum(axis=0)).ravel())
370370
).items()
371371
}
372372

@@ -404,7 +404,6 @@ def vectorization(feature_name, series, mean_document_length):
404404

405405
@staticmethod
406406
def build(name, series, is_cjk, is_html):
407-
408407
internal = {"cjk": is_cjk, "html": is_html}
409408

410409
if is_cjk:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"python_jsonschema_objects>=0.3.13",
3030
"PyYAML>=6", # pyyaml 5.4 is broken with cython 3
3131
"requests",
32-
"scikit-learn>=0.23.2,<1.2",
32+
"scikit-learn>=1.0",
3333
"tabulate>=0.8.9",
3434
"tqdm>=4.59.0",
3535
"psutil>=5.7.2",

tests/unitary/with_extras/hpo/test_hpo_search_space.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
"""Contains tests for ads.hpo.search_space
77
"""
88

9-
import unittest
109
import lightgbm
1110
import pytest
1211
import sklearn
1312
import xgboost
14-
import sys, mock
1513

1614
from ads.hpo.stopping_criterion import *
1715
from ads.hpo.distributions import *

0 commit comments

Comments
 (0)