shankarpandala / lazypredict

Lazy Predict help build a lot of basic models without much code and helps understand which models works better without any parameter tuning
MIT License
2.78k stars 321 forks source link

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

Open Rushi21-kesh opened 3 years ago

Rushi21-kesh commented 3 years ago

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'
adarshchbs commented 3 years ago

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

WOKNz commented 3 years ago

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

sanromd commented 3 years ago

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))]
Josephsmurph13 commented 3 years ago

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?

naveen-marthala commented 3 years ago

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
am-official commented 3 years ago

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)