'"Trying to unpickle estimator LinearRegression from version X when using version Y" - But I have only the Y version on my .venv, what takes?

The exact warning is ....\.venv\lib\site-packages\sklearn\base.py:329: UserWarning: Trying to unpickle estimator LinearRegression from version 0.24.1 when using version 1.0.2. This might lead to breaking code or invalid results. Use at your own risk.

I saw several questions on this matter here and on other forums - they all sum up in uninstall and install the latter version.

I tried that, but still getting the error. Moreover, the model building and the consumer are on the same VSCode worksapce using the same .venv which holds scikit-learn==1.0.2 - so where does the 0.24.1 come from and more important, how can I solve this warning and be sure my predictions are true?

EDIT per @rickhg12hs request:

the code part is very basic:

self.ModelHeight = pickle.load(open(filePath, "rb")


Solution 1:[1]

Your case

I think (or maybe am pretty sure) that it's about the version of sklearn with which your pickle model was created-- that mismatches the sklearn version with which you are loading the model.

In your case

pip install scikit-learn==1.0.2 

should do the trick.


My case

In my case, I tried to resolve the following warning message

/home/partha/anaconda3/lib/python3.7/site-packages/sklearn/base.py:334: 
UserWarning: Trying to unpickle estimator LinearRegression from version 1.1.1 
when using version 0.23.2. This might lead to breaking code or invalid results. 
Use at your own risk.
  UserWarning)

with

pip install scikit-learn==1.1.1

but the documentation of the version says :

Version 1.1.0 of scikit-learn requires python 3.8+, ...

whereas I am running python 3.7 !


Caveat

Hopefully your conflict with version 1.0.1 should be solved, as its documentation says :

Version 1.0.0 of scikit-learn requires python 3.7+, ...

though other dependencies on your existing version (0.24.1) of scikit-learn is not guaranteed here !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1