unit8co / darts

A python library for user-friendly forecasting and anomaly detection on time series.
https://unit8co.github.io/darts/
Apache License 2.0
7.56k stars 829 forks source link

[BUG] Scikit Learn Import Breaking #2203

Closed barmanroys closed 2 months ago

barmanroys commented 5 months ago

Describe the bug Using the catboost model with darts. When building the virtual environment for my inference pipeline, I run this command inside my docker container python3 -m pip install --user darts==0.27.2 # Latest as of this report This installs scikit-learn 1.4.0 as a dependency, which it cannot work with.

To Reproduce Try this in your sandbox pip environment python3 -m pip install --user darts==0.27.2 # Latest as of this question

Then try using the models like this

from darts.models.forecasting.linear_regression_model import LinearRegressionModel

Expected behavior I expect the models to be imported as expected.

System (please complete the following information):

Traceback

from darts.models.forecasting.linear_regression_model import LinearRegressionModel
  File "/[app/.venv/lib/python3.11/site-packages/darts/models/forecasting/linear_regression_model.py](http://app/.venv/lib/python3.11/site-packages/darts/models/forecasting/linear_regression_model.py)", line 15, in <module>
    from darts.models.forecasting.regression_model import (
  File "/[app/.venv/lib/python3.11/site-packages/darts/models/forecasting/regression_model.py](http://app/.venv/lib/python3.11/site-packages/darts/models/forecasting/regression_model.py)", line 55, in <module>
    from darts.utils.multioutput import MultiOutputRegressor
  File "/[app/.venv/lib/python3.11/site-packages/darts/utils/multioutput.py](http://app/.venv/lib/python3.11/site-packages/darts/utils/multioutput.py)", line 5, in <module>
    from sklearn.utils.validation import _check_fit_params, has_fit_parameter
ImportError: cannot import name '_check_fit_params' from 'sklearn.utils.validation' (/[app/.venv/lib/python3.11/site-packages/sklearn/utils/validation.py](http://app/.venv/lib/python3.11/site-packages/sklearn/utils/validation.py))
dennisbader commented 5 months ago

This is very strange, as it only seems to be happening when running from a docker container (see #2188).

We actually already fixed the import error (from sklearn == 1.4.0) in darts==0.27.2 for both PyPi and conda. The fix is here: https://github.com/unit8co/darts/blob/8cb04f67982bd3c77016bdd5fbdd928bf7d11bf7/darts/utils/multioutput.py#L8

Can you run the following from inside the container and show us the output?

from sklearn import __version__ as sklearn_version
print(sklearn_version)

if sklearn_version >= "1.4":
    print("works fine")
else:
    print("does not work")
dennisbader commented 5 months ago

Looking at your error message again, the line where it fails is from an older darts version <0.27.2.

Can you verify that indeed darts==0.27.2 is installed?

From python:

import darts
print(darts.__version__)