lazypredict icon indicating copy to clipboard operation
lazypredict copied to clipboard

ModuleNotFoundError: No module named 'sklearn.utils.testing'

Open Rushi21-kesh opened this issue 3 years ago • 6 comments

  • Lazy Predict version: '0.2.7'
  • Python version: 3.8.0
  • Sklearn version : 0.21.3 / 0.23.1 / 0.24.1
  • Operating System: Windows 10

Description

I'm trying to Import LazyRegressor from lazypredict.Supervised

But while importing I'm getting an error " ModuleNotFoundError: No module named 'sklearn.utils.testing' ". I try it by installing Sklearn version: 0.21.3 / 0.23.1 / 0.24.1 but the same error is raised everytime ( I did all this in new env )

What I Did

import lazypredict
from lazypredict.Supervised import LazyRegressor

Output :
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-12-340b76a5a8e6> in <module>
      1 import lazypredict
----> 2 from lazypredict.Supervised import LazyRegressor

d:\ds env\python\lib\site-packages\lazypredict\Supervised.py in <module>
     14 from sklearn.preprocessing import StandardScaler, OneHotEncoder
     15 from sklearn.compose import ColumnTransformer
---> 16 from sklearn.utils.testing import all_estimators
     17 from sklearn.base import RegressorMixin
     18 from sklearn.base import ClassifierMixin

ModuleNotFoundError: No module named 'sklearn.utils.testing'

Rushi21-kesh avatar Apr 17 '21 11:04 Rushi21-kesh

Change the sklearn version to 23.x instead of 24.x.

adarshchbs avatar Apr 23 '21 17:04 adarshchbs

from sklearn.utils.testing import all_estimators to from sklearn.testing import all_estimators

WOKNz avatar Apr 29 '21 18:04 WOKNz

I came across the same problem that @Rushi21-kesh mentioned. The ModuleNotFoundError arises when removing classifiers and regressors. I solved the issue by modifying the firs couple of lines in Supervised.py. @shankarpandala Instead of building a list of tupples (estimator_name, sklearn.moduleX) to remove, create a list with estimator_name to remove, then use it in the list comprehension to remove them. This effectively makes the code run with sklearn 0.23.x and 0.24.x

removed_classifiers = [
    "ClassifierChain",
    "ComplementNB",
    "GradientBoostingClassifier",
    "GaussianProcessClassifier",
    "HistGradientBoostingClassifier",
    "MLPClassifier",
    "LogisticRegressionCV", 
    "MultiOutputClassifier", 
    "MultinomialNB", 
    "OneVsOneClassifier",
    "OneVsRestClassifier",
    "OutputCodeClassifier",
    "RadiusNeighborsClassifier",
    "VotingClassifier",
]

removed_regressors = [
    "TheilSenRegressor",
    "ARDRegression", 
    "CCA", 
    "IsotonicRegression", 
    "StackingRegressor",
    "MultiOutputRegressor", 
    "MultiTaskElasticNet", 
    "MultiTaskElasticNetCV", 
    "MultiTaskLasso", 
    "MultiTaskLassoCV", 
    "PLSCanonical", 
    "PLSRegression", 
    "RadiusNeighborsRegressor", 
    "RegressorChain", 
    "VotingRegressor", 
]
CLASSIFIERS = [est for est in all_estimators() if 
               (issubclass(est[1], ClassifierMixin) and (est[0] not in removed_classifiers))]

REGRESSORS = [est for est in all_estimators() if 
              (issubclass(est[1], RegressorMixin) and (est[0] not in removed_regressors))]

sanromd avatar May 14 '21 12:05 sanromd

Apologies, I am very new to python. I am getting the same error ModuleNotFoundError: No module named 'sklearn.utils.testing'.

Is this issue likely to be fixed in a new version soon? I am unable to install previous versions of lazypredict.

Do we know if editing the Supervised.py under the lazypredict site-packages folder fixes this? If so please could someone share the full contents of the file to update?

Josephsmurph13 avatar Jun 14 '21 11:06 Josephsmurph13

I have the same error and I am using sklearn 0.24.x.

user@name::~$ pip freeze | grep -i 'learn'
imbalanced-learn==0.7.0
scikit-learn==0.24.2
sklearn==0.0
umap-learn==0.5.1
user@name::~$ pip freeze | grep -i 'lazy'
lazypredict==0.2.9

naveen-marthala avatar Jul 02 '21 11:07 naveen-marthala

Those who are facing ModuleNotFoundError: No module named 'sklearn.utils.testing'

import sklearn
estimators = sklearn.utils.all_estimators(type_filter=None)
for name, class_ in estimators:
    if hasattr(class_, 'predict_proba'):
        print(name)

am-official avatar Jul 13 '21 20:07 am-official