I am getting the following error when I tried to upgrade my application's python version from 2.x to 3.9.
ERROR - ModuleNotFoundError: No module named 'sklearn.linear_model.stochastic_gradient'
Any idea in which version the module 'sklearn.linear_model.stochastic_gradient' got deprecated or which version of python 3.x should I use for backward compatibility?
platform darwin -- Python 3.9.13
pytest-7.1.3
pluggy-1.0.0
Complete error logs:
=========================================================================== ERRORS ===========================================================================
_______________________________________________________________ ERROR collecting test session ________________________________________________________________
/usr/local/Caskroom/miniforge/base/lib/python3.9/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1030: in _gcd_import
???
<frozen importlib._bootstrap>:1007: in _find_and_load
???
<frozen importlib._bootstrap>:986: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:680: in _load_unlocked
???
/usr/local/Caskroom/miniforge/base/lib/python3.9/site-packages/_pytest/assertion/rewrite.py:168: in exec_module
exec(co, module.__dict__)
tests/main_app_tests/conftest.py:7: in <module>
import app as app_py
app.py:14: in <module>
from main_app.resources import (mapper,
main_app/resources/mapper.py:3: in <module>
from main_app.common import util
main_app/common/util.py:7: in <module>
from application.util import logger
application/util.py:234: in <module>
models = load_all_models()
data_science/classifier.py:208: in load_all_models
models[id] = load_model(id)
data_science/classifier.py:177: in load_model
clf = load(model_path)
/usr/local/Caskroom/miniforge/base/lib/python3.9/site-packages/joblib/numpy_pickle.py:656: in load
return load_compatibility(fobj)
/usr/local/Caskroom/miniforge/base/lib/python3.9/site-packages/joblib/numpy_pickle_compat.py:231: in load_compatibility
obj = unpickler.load()
/usr/local/Caskroom/miniforge/base/lib/python3.9/pickle.py:1212: in load
dispatch[key[0]](self)
/usr/local/Caskroom/miniforge/base/lib/python3.9/pickle.py:1528: in load_global
klass = self.find_class(module, name)
/usr/local/Caskroom/miniforge/base/lib/python3.9/pickle.py:1579: in find_class
__import__(module, level=0)
E ModuleNotFoundError: No module named 'sklearn.linear_model.stochastic_gradient'
====================================================================== warnings summary ======================================================================
CodePudding user response:
Install this: pip install scikit-learn --upgrade
CodePudding user response:
That's because the actual module name is _stochastic_gradient
.
The modules preceded by _
are private modules, they act as implementation of standard public modules. You should not import those modules directly.
To see the list of all modules present under sklearn.linear_model
you can enter
dir(sklearn.linear_model)
that will show private and public modules
Everything you need for stochastic gradient you can find in SGDClassifier
or SGDRegressor