mindsdb / lightwood

Lightwood is Legos for Machine Learning.
GNU General Public License v3.0
442 stars 93 forks source link

ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' #75

Closed ZoranPandovski closed 4 years ago

ZoranPandovski commented 4 years ago

Describe the bug Installing the latest version of lightwood throws ImportError. I guess the issue is related to the sciki-learn.

To Reproduce Steps to reproduce the behavior:

  1. Train model, the issue is not related to a specific dataset
  2. See error
from cesium import featurize

File "/home/zoran/MyProjects/lightwood/l/lib/python3.7/site-packages/cesium-0.9.9-py3.7-linux-x86_64.egg/cesium/featurize.py", line 10, in from sklearn.preprocessing import Imputer ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (/home/zoran/MyProjects/lightwood/l/lib/python3.7/site-packages/scikit_learn-0.22rc3-py3.7-linux-x86_64.egg/sklearn/preprocessing/init.py)

Screenshots Screenshot from 2019-12-02 14-40-15

ZoranPandovski commented 4 years ago

This is related with pip installing latest verzion of scikit-learn which was pre-release 0.22rc3 version. We should use fixed version that works 0.21.3. I will create PR

ZoranPandovski commented 4 years ago

A new scikit-learn version 0.22 was released yesterday, but there are other errors with using that version. We should keep on 0.21.3 for now.

ZoranPandovski commented 4 years ago

Fixed by #74

AnasK95 commented 4 years ago

from sklearn.impute import SimpleImputer will work because of the following

DeprecationWarning: Class Imputer is deprecated; Imputer was deprecated in version 0.20 and will be removed in 0.22. Import impute.SimpleImputer from sklearn instead.

subhashi commented 4 years ago

Thank you @AnasK95 It worked.

So I had to use,

from sklearn.impute import SimpleImputer 
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')

instead of

from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values='NaN', strategy='mean', axis=0)

Otherwise, it gives the following error.

from sklearn.preprocessing import Imputer
ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing'
KavishGoyal commented 4 years ago

Thanks @AnasK95 and @subhashi It worked for me as well.

AnujJha-stack commented 4 years ago

thanks it works

jspw commented 4 years ago

but 'axis' is no more a argument there ! btw tahnks @AnasK95 it worked!

harmeshm commented 4 years ago

Thank you @AnasK95.

Rawkush commented 4 years ago

Thank you @AnasK95 It worked. but how do we use axis argument functionality now?

MutumaIan commented 4 years ago

Thanks a lot.

diegoecon-ai commented 4 years ago

Sincerely thanks! @AnasK95

Norni commented 4 years ago

Thanks @subhashi

ahmedtamam721 commented 4 years ago

i try to upgrade it but !!!

siket learn

dpk-a7 commented 4 years ago

hey, In version 0.22.2, for error: ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (C:\Users\Anaconda3\lib\site-packages\sklearn\preprocessing__init__.py)

You can use this snippet, and it will work fine: (C:\Users\Anaconda3\lib\site-packages\sklearn\preprocessing__init__.py)

from .imputation import Imputer

all = [ . . .

'Imputer',             #  type 'imputer'

. . . ] <-------------------------------------------------------------> Hope this would help <------------------------------------------------------------> full init.py code here:

""" The :mod:sklearn.preprocessing module includes scaling, centering, normalization, binarization and imputation methods. """

from ._function_transformer import FunctionTransformer

from .data import Binarizer from .data import KernelCenterer from .data import MinMaxScaler from .data import MaxAbsScaler from .data import Normalizer from .data import RobustScaler from .data import StandardScaler from .data import QuantileTransformer from .data import add_dummy_feature from .data import binarize from .data import normalize from .data import scale from .data import robust_scale from .data import maxabs_scale from .data import minmax_scale from .data import quantile_transform from .data import power_transform from .data import PowerTransformer from .data import PolynomialFeatures

from ._encoders import OneHotEncoder from ._encoders import OrdinalEncoder

from .label import label_binarize from .label import LabelBinarizer from .label import LabelEncoder from .label import MultiLabelBinarizer

from ._discretization import KBinsDiscretizer

from .imputation import Imputer

all = [ 'Binarizer', 'FunctionTransformer', 'Imputer', 'KBinsDiscretizer', 'KernelCenterer', 'LabelBinarizer', 'LabelEncoder', 'MultiLabelBinarizer', 'MinMaxScaler', 'MaxAbsScaler', 'QuantileTransformer', 'Normalizer', 'OneHotEncoder', 'OrdinalEncoder', 'PowerTransformer', 'RobustScaler', 'StandardScaler', 'add_dummy_feature', 'PolynomialFeatures', 'binarize', 'normalize', 'scale', 'robust_scale', 'maxabs_scale', 'minmax_scale', 'label_binarize', 'quantile_transform', 'power_transform', 'Imputer' ]

Yassir-Alharbi commented 4 years ago

This was sorted by, https://github.com/scikit-learn/scikit-learn/issues/16152

jhhalls commented 4 years ago

This is related with pip installing latest verzion of scikit-learn which was pre-release 0.22rc3 version. We should use fixed version that works 0.21.3. I will create PR

How do i downgrade scikit-learn from 0.22.2 to 0.21

Etherum7 commented 4 years ago

Thanks @AnasK95 and @subhashi it helps Cheers to all who are in hadelin machine learning course

ambujbhargava commented 4 years ago

For me I used SimpleImputer

from sklearn.impute import SimpleImputer

worked.

rohitbajpai1 commented 4 years ago

from sklearn.impute import SimpleImputer

imputer = SimpleImputer(missing_values = np.nan, strategy='mean') X.fit[:, 1:3] = imputer.fit_transform(X[:, 1:3]) X = X.apply(lambda x: x.fillna(x.value_counts().index[0]))

(slice(None, None, None), slice(1, 3, None))' is an invalid key

Still getting this error

sudhirp93 commented 3 years ago

ImportError: cannot import name 'MinMaxScalar' from sklearn.preprocessing .... any help?

PatChandresh commented 2 years ago

I used from sklearn.impute import SimpleImputer imputer = SimpleImputer(strategy='median')

instead of from sklearn.preprocessing import Imputer imputer = Imputer(strategy="median")

not throwing any error

arefehsajedi commented 2 years ago

Hey there,

I just confronted similar error, and I found out the reason was version of the sciki-learn.. in the latest version , you should code as : from sklearn.impute import SimpleImputer instead of : from sklearn.preprocessing import Imputer

also note that inputs are as following: SimpleImputer(missing_values=np.nan, strategy='mean')

also regarding using np, you should summon numpy library. besides, there is no required parameter as axis=0 or 1