Skip to content

Commit

Permalink
&hazrulakmal [MNT] fix remaining sklearn 1.3.0 compatibility issues (
Browse files Browse the repository at this point in the history
…#4860)

There are some remaining compatibility issues from the `sklearn 1.3.0`
release which the pre-release testing did not catch. See
#4778. This PR fixes those.

* `ElasticEnsemble` instantiated `sklearn` `RandomizedSearchCV` with
`float` `n_iter`, which sets off the parameter validation since 1.3.0.
Fixed by coercing to `int` (rounding down)
* `MatrixProfileClassifier` fails due to `sklearn` bug
scikit-learn/scikit-learn#26768. This is 1.3.0
specific and appears fixed for (not yet released) 1.3.1, so added an
`sklearn!=1.3.0` version requirement for `MatrixProfileClassifier`

Depends on the bugfix #4867 to
ensure the specifier `sklearn!=1.3.0` is handled correctly.
  • Loading branch information
fkiraly committed Jul 11, 2023
1 parent 645fabc commit 8e9ad16
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/source/developer_guide/dependencies.rst
Expand Up @@ -42,7 +42,7 @@ Estimators with a soft dependency need to ensure the following:
or a ``list`` of ``str``, of import dependencies. Exceptions will automatically raised when constructing the estimator
in an environment without the required packages.
* In a case where the package import differs from the package name, i.e., ``import package_string`` is different from
``pip install different-package-string`` (usually the case for packages containing a dash in the name), the ``python_dependecies_alias`` tag
``pip install different-package-string`` (usually the case for packages containing a dash in the name), the ``python_dependencies_alias`` tag
should be populated to pass the information on package and import strings as ``dict`` such as ``{"scikit-learn":"sklearn"}``.
* If the soft dependencies require specific python versions, the ``python_version``
tag should also be populated, with a PEP 440 compliant version specification ``str`` such as ``"<3.10"`` or ``">3.6,~=3.8"``.
Expand Down
2 changes: 1 addition & 1 deletion sktime/alignment/dtw_python.py
Expand Up @@ -51,7 +51,7 @@ class AlignerDTW(BaseAligner):
"capability:distance": True, # does compute/return overall distance?
"capability:distance-matrix": True, # does compute/return distance matrix?
"python_dependencies": "dtw-python",
"python_dependecies_alias": {"dtw-python": "dtw"},
"python_dependencies_alias": {"dtw-python": "dtw"},
}

def __init__(
Expand Down
3 changes: 3 additions & 0 deletions sktime/base/_base.py
Expand Up @@ -357,6 +357,9 @@ class BaseEstimator(BaseObject):
Extends sktime's BaseObject to include basic functionality for fittable estimators.
"""

# global dependency alias tag for sklearn dependency management
_tags = {"python_dependencies_alias": {"scikit-learn": "sklearn"}}

def __init__(self):
self._is_fitted = False
super().__init__()
Expand Down
2 changes: 1 addition & 1 deletion sktime/classification/distance_based/_elastic_ensemble.py
Expand Up @@ -290,7 +290,7 @@ def _fit(self, X, y):
param_distributions=ElasticEnsemble._get_100_param_options(
self.distance_measures[dm], X
),
n_iter=100 * self.proportion_of_param_options,
n_iter=int(100 * self.proportion_of_param_options),
cv=LeaveOneOut(),
scoring="accuracy",
n_jobs=self._threads_to_use,
Expand Down
Expand Up @@ -57,17 +57,20 @@ class MatrixProfileClassifier(BaseClassifier):
>>> from sktime.classification.feature_based import MatrixProfileClassifier
>>> from sktime.datasets import load_unit_test
>>> X_train, y_train = load_unit_test(split="train", return_X_y=True)
>>> X_test, y_test = load_unit_test(split="test", return_X_y=True)
>>> clf = MatrixProfileClassifier()
>>> clf.fit(X_train, y_train)
MatrixProfileClassifier(...)
>>> y_pred = clf.predict(X_test)
>>> X_test, y_test = load_unit_test(split="test", return_X_y=True) # doctest: +SKIP
>>> clf = MatrixProfileClassifier() # doctest: +SKIP
>>> clf.fit(X_train, y_train) # doctest: +SKIP
MatrixProfileClassifier(...) # doctest: +SKIP
>>> y_pred = clf.predict(X_test) # doctest: +SKIP
"""

_tags = {
"capability:multithreading": True,
"capability:predict_proba": True,
"classifier_type": "distance",
# sklearn 1.3.0 has a bug which causes predict_proba to fail
# see scikit-learn#26768 and sktime#4778
"python_dependencies": "scikit-learn!=1.3.0",
}

def __init__(
Expand Down

0 comments on commit 8e9ad16

Please sign in to comment.