Python Forum

Full Version: Which app do I import to fix this error?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In the following snippet of code, I made a replacement:

import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import Imputer
import matplotlib.pyplot as plt

%matplotlib inline
The new code is

import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Imputer
import matplotlib.pyplot as plt

%matplotlib inline
I replaced cross_validation in line 4 with model selection. It worked.



Now I get the following error when I run the code.









Error:
ImportError Traceback (most recent call last) <ipython-input-11-8cc04663b4cc> in <module> 3 from sklearn.linear_model import LinearRegression 4 from sklearn.model_selection import train_test_split ----> 5 from sklearn.preprocessing import Imputer 6 import matplotlib.pyplot as plt 7 ImportError: cannot import name 'Imputer' from 'sklearn.preprocessing' (/opt/conda/lib/python3.7/site-packages/sklearn/preprocessing/__init__.py)
Now I am confused since when I ran pip list and conda list I got that

sklearn 0.0

see attached screenshot. What import app covers this function?

It seems that I have sklearn 0.0 installed. That make no sense.

HowdoI correct this error. Is this handled by scikit-learn?

I am not sure what to do.

Respectfully,

ErnestTBass
Are you sure Imputer exists in sklearn.preprocessing? Maybe you can have a look on the actual source code from sklearn.preprocessing. Perhaps you can find out what Imputer is supposed to be.
After scikit-learn version 0.20.
>>> from sklearn.impute import SimpleImputer
>>>
(Apr-25-2020, 07:50 PM)ErnestTBass Wrote: [ -> ]It seems that I have sklearn 0.0 installed. That make no sense.
>>> from sklearn import base

>>> base.__version__
'0.22.2.post1'
I don't think imputer is where you thing.
See sklearn imputer search
Wait, now. You are saying to install a later version of sklearn and then use the syntax that you
put in your post?


I will give it a try.


Again, what is with this sklearn version 0.0. That really makes no sense at all.

How did I or someone install sklearn 0.0. That to me means that sklearn simply was not installed. Period.

Respectfully,

ErnestTBass
That would be a bad assumption. You would get an error on the import
Update scikit-learn. 0.22.2 is the current stable version.
(Apr-26-2020, 07:48 PM)ErnestTBass Wrote: [ -> ]Wait, now. You are saying to install a later version of sklearn and then use the syntax that you
put in your post?
No you get that error because you use a never version.
# This only work in older version that's why you get a error
from sklearn.preprocessing import Imputer

# This is what you should now in newer versions,this dos now just he same as line over 
from sklearn.impute import SimpleImputer
ErnestTBass Wrote:Again, what is with this sklearn version 0.0. That really makes no sense at all.
How dos you check to get this?
I did show you how to check version.
>>> from sklearn import base
 
>>> base.__version__
'0.22.2.post1'