Skip to content

Commit

Permalink
More schema depreciations from sklearn 1.2 and removal for 1.4
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Shinnar <[email protected]>
  • Loading branch information
shinnar committed Feb 7, 2024
1 parent f3beff7 commit df4225b
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 3 deletions.
26 changes: 26 additions & 0 deletions lale/lib/autogen/calibrated_classifier_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,31 @@ def predict_proba(self, X):
set_as_available=True,
)

if sklearn_version >= version.Version("1.2"):
CalibratedClassifierCV = CalibratedClassifierCV.customize_schema(
base_estimator={
"anyOf": [
{"laleType": "operator"},
{"enum": ["deprecated"]},
],
"default": "deprecated",
"description": "Deprecated. Use `estimator` instead.",
},
estimator={
"anyOf": [
{"laleType": "operator"},
{"enum": [None], "description": "LinearSVC"},
],
"default": None,
"description": "The base estimator to fit on random subsets of the dataset.",
},
set_as_available=True,
)

if sklearn_version >= version.Version("1.4"):
CalibratedClassifierCV = CalibratedClassifierCV.customize_schema(
base_estimator=None, set_as_available=True
)


set_docstrings(CalibratedClassifierCV)
94 changes: 93 additions & 1 deletion lale/lib/autogen/mini_batch_sparse_pca.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from numpy import inf, nan
from packaging import version
from sklearn.decomposition import MiniBatchSparsePCA as Op

from lale.docstrings import set_docstrings
from lale.operators import make_operator
from lale.operators import make_operator, sklearn_version


class _MiniBatchSparsePCAImpl:
Expand Down Expand Up @@ -189,4 +190,95 @@ def transform(self, X):
}
MiniBatchSparsePCA = make_operator(_MiniBatchSparsePCAImpl, _combined_schemas)

if sklearn_version >= version.Version("1.1"):
MiniBatchSparsePCA = MiniBatchSparsePCA.customize_schema(
max_no_improvement={
"anyOf": [
{
"type": "integer",
"minimum": 1,
},
{
"enum": [None],
"description": "Disable convergence detection based on cost function.",
},
],
"default": 10,
"description": "Control early stopping based on the consecutive number of mini batches that does not yield an improvement on the smoothed cost function.",
},
tol={
"type": "number",
"default": 0.001,
"description": """Control early stopping based on the norm of the differences in the dictionary between 2 steps.
To disable early stopping based on changes in the dictionary, set tol to 0.0.""",
},
set_as_available=True,
)

if sklearn_version >= version.Version("1.2"):
MiniBatchSparsePCA = MiniBatchSparsePCA.customize_schema(
max_iter={
"anyOf": [
{
"type": "integer",
"minimumForOptimizer": 5,
"maximumForOptimizer": 1000,
"distribution": "uniform",
"default": 1000,
},
{"enum": [None]},
],
"description": "Maximum number of iterations over the complete dataset before stopping independently of any early stopping criterion heuristics. If max_iter is not None, n_iter is ignored.",
"default": None,
},
n_iter={
"anyOf": [
{
"type": "integer",
"minimumForOptimizer": 5,
"maximumForOptimizer": 1000,
"distribution": "uniform",
"default": 1000,
},
{"enum": ["deprecated"]},
],
"description": "total number of iterations to perform",
"default": "deprecated",
},
set_as_available=True,
)

if sklearn_version >= version.Version("1.4"):
MiniBatchSparsePCA = MiniBatchSparsePCA.customize_schema(
max_iter={
"anyOf": [
{
"type": "integer",
"minimumForOptimizer": 5,
"maximumForOptimizer": 1000,
"distribution": "uniform",
},
{"enum": [None], "description": "deprecated"},
],
"description": "Maximum number of iterations over the complete dataset before stopping independently of any early stopping criterion heuristics.",
"default": 1000,
},
n_iter=None,
set_as_available=True,
)

if sklearn_version >= version.Version("1.6"):
MiniBatchSparsePCA = MiniBatchSparsePCA.customize_schema(
max_iter={
"type": "integer",
"minimumForOptimizer": 5,
"maximumForOptimizer": 1000,
"distribution": "uniform",
"default": 1000,
"description": "Maximum number of iterations over the complete dataset before stopping independently of any early stopping criterion heuristics.",
},
set_as_available=True,
)

set_docstrings(MiniBatchSparsePCA)
2 changes: 1 addition & 1 deletion lale/lib/sklearn/ada_boost_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def score(self, X, y, sample_weight=None):
set_as_available=True,
)

if lale.operators.sklearn_version >= version.Version("1.5"):
if lale.operators.sklearn_version >= version.Version("1.4"):
AdaBoostClassifier = AdaBoostClassifier.customize_schema(
base_estimator=None,
set_as_available=True,
Expand Down
2 changes: 1 addition & 1 deletion lale/lib/sklearn/ada_boost_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def score(self, X, y, sample_weight=None):
set_as_available=True,
)

if lale.operators.sklearn_version >= version.Version("1.5"):
if lale.operators.sklearn_version >= version.Version("1.4"):
AdaBoostRegressor = AdaBoostRegressor.customize_schema(
base_estimator=None, set_as_available=True
)
Expand Down
18 changes: 18 additions & 0 deletions lale/lib/sklearn/bagging_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,22 @@ def score(self, X, y, sample_weight=None):
set_as_available=True,
)

if lale.operators.sklearn_version >= version.Version("1.3"):
BaggingClassifier = BaggingClassifier.customize_schema(
base_estimator={
"anyOf": [
{"laleType": "operator"},
{"enum": ["deprecated", None]},
],
"default": "deprecated",
"description": "Deprecated. Use `estimator` instead.",
},
set_as_available=True,
)

if lale.operators.sklearn_version >= version.Version("1.4"):
BaggingClassifier = BaggingClassifier.customize_schema(
base_estimator=None, set_as_available=True
)

lale.docstrings.set_docstrings(BaggingClassifier)
5 changes: 5 additions & 0 deletions lale/lib/sklearn/bagging_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,9 @@ def score(self, X, y, sample_weight=None):
set_as_available=True,
)

if lale.operators.sklearn_version >= version.Version("1.4"):
BaggingRegressor = BaggingRegressor.customize_schema(
base_estimator=None, set_as_available=True
)

lale.docstrings.set_docstrings(BaggingRegressor)
15 changes: 15 additions & 0 deletions lale/lib/sklearn/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,19 @@ def score(self, X, y, sample_weight=None):
),
)

if lale.operators.sklearn_version >= version.Version("1.4"):
# old: https://scikit-learn.org/1.1/modules/generated/sklearn.linear_model.LogisticRegression.html
# new: https://scikit-learn.org/1.2/modules/generated/sklearn.linear_model.LogisticRegression.html
LogisticRegression = typing.cast(
lale.operators.PlannedIndividualOp,
LogisticRegression.customize_schema(
penalty=Enum(
values=["l1", "l2", "elasticnet", None],
desc="Norm used in the penalization.",
default="l2",
),
set_as_available=True,
),
)

lale.docstrings.set_docstrings(LogisticRegression)
4 changes: 4 additions & 0 deletions lale/lib/sklearn/one_hot_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,9 @@ def transform_schema(self, s_X):
set_as_available=True,
)

if sklearn_version >= version.Version("1.4"):
# new: https://scikit-learn.org/1.2/modules/generated/sklearn.preprocessing.OneHotEncoder.html
OneHotEncoder = OneHotEncoder.customize_schema(sparse=None, set_as_available=True)


lale.docstrings.set_docstrings(OneHotEncoder)

0 comments on commit df4225b

Please sign in to comment.