Search code examples
pythonazure-databrickspycaretsktime

pycaret.time_series.TSForecastingExperiment ImportError: cannot import name '_check_param_grid' from 'sklearn.model_selection._search'


I am getting the below error, while importing Pycaret time-series(beta) module in the databricks (we were running successfully earlier). Request your help in solving the issues.

pycaret version in use:

import pycaret
pycaret.__version__  # Out[1]: '3.0.0'

python version in use:

import sys
sys.version #Out[9]: '3.8.10 (default, Mar 15 2022, 12:22:08) \n[GCC 9.4.0]'

Below is the stack trace for the issue.

from pycaret.time_series import TSForecastingExperiment

/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
    160             # Import the desired module. If you’re seeing this while debugging a failed import,
    161             # look at preceding stack frames for relevant error information.
--> 162             original_result = python_builtin_import(name, globals, locals, fromlist, level)
    163 
    164             is_root_import = thread_local._nest_level == 1

/databricks/python/lib/python3.8/site-packages/pycaret/time_series/__init__.py in <module>
----> 1 from pycaret.time_series.forecasting.oop import TSForecastingExperiment
      2 from pycaret.time_series.forecasting.functional import (
      3     setup,
      4     create_model,
      5     compare_models,

/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
    160             # Import the desired module. If you’re seeing this while debugging a failed import,
    161             # look at preceding stack frames for relevant error information.
--> 162             original_result = python_builtin_import(name, globals, locals, fromlist, level)
    163 
    164             is_root_import = thread_local._nest_level == 1

/databricks/python/lib/python3.8/site-packages/pycaret/time_series/forecasting/oop.py in <module>
     14 from sklearn.base import clone
     15 from sktime.forecasting.base import ForecastingHorizon
---> 16 from sktime.forecasting.model_selection import (
     17     temporal_train_test_split,
     18     ExpandingWindowSplitter,

/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
    160             # Import the desired module. If you’re seeing this while debugging a failed import,
    161             # look at preceding stack frames for relevant error information.
--> 162             original_result = python_builtin_import(name, globals, locals, fromlist, level)
    163 
    164             is_root_import = thread_local._nest_level == 1

/databricks/python/lib/python3.8/site-packages/sktime/forecasting/model_selection/__init__.py in <module>
     20 from sktime.forecasting.model_selection._split import SlidingWindowSplitter
     21 from sktime.forecasting.model_selection._split import temporal_train_test_split
---> 22 from sktime.forecasting.model_selection._tune import ForecastingGridSearchCV
     23 from sktime.forecasting.model_selection._tune import ForecastingRandomizedSearchCV

/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py in import_patch(name, globals, locals, fromlist, level)
    160             # Import the desired module. If you’re seeing this while debugging a failed import,
    161             # look at preceding stack frames for relevant error information.
--> 162             original_result = python_builtin_import(name, globals, locals, fromlist, level)
    163 
    164             is_root_import = thread_local._nest_level == 1

/databricks/python/lib/python3.8/site-packages/sktime/forecasting/model_selection/_tune.py in <module>
     11 from sklearn.base import clone
     12 from sklearn.model_selection import ParameterGrid, ParameterSampler, check_cv
---> 13 from sklearn.model_selection._search import _check_param_grid
     14 from sklearn.utils.metaestimators import if_delegate_has_method

Solution

  • This is due to the use of a private method from sklearn in the sktime dependency. Since sklearn updated to 1.1.0, this private method was removed/moved, hence it is breaking. The sktime team is working on fixing this. In the meantime, you can fix this by force installing sklearn 1.0.2.

    Please see the details in the GitHub Repo: https://github.com/pycaret/pycaret/issues/2542