I'm trying to deploy a LogisticRegression model on an active cloud shell that was trained using scikit-learn version 1.3.0, but I'm getting the following warning message:

/usr/local/lib/python3.9/site-packages/sklearn/base.py:310: UserWarning: Trying to unpickle estimator LogisticRegression from version 1.3.0 when using version 0.24.2. This might lead to breaking code or invalid results. Use at your own risk. warnings.warn(

What does this warning message mean and how do I fix it?

I'm using:

  • Python 3.9.
  • scikit-learn 0.24.2.

I've tried upgrading scikit-learn to version 1.3.0, but the warning message persists.

1

There are 1 best solutions below

0
DataJanitor On

It is recommended to only load a model that was created with the same version of the package that you are currently using. The reason for this is that the inner workings or even the precision of numerical calculations might have changed.

Try to imagine it like this (fictive and totally exaggerated):

You load some bytes. With version 0.24.2 this was translated to the letter 'a', while with version 1.3 this will be translated to the number 1.0.

There are some solutions to this:

  • Match the versions, as you already tried. You can use pip install scikit-learn==1.3.0 or similar. Then, at least scikit-learn won't be the cause of the error anymore. The warning may then point to another version mismatch.
  • Retrain the model with the version you are using right now.
  • Use a requirements.txt file to store your package versions and create your virtual environment based on this file, ensuring all required versions are installed.