Python Forum
Which app do I import to fix this error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Which app do I import to fix this error?
#1
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
Reply
#2
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.
- Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. Albert Einstein
Reply
#3
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'
Reply
#4
I don't think imputer is where you thing.
See sklearn imputer search
Reply
#5
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
Reply
#6
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.
Reply
#7
(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'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  import module with syntax error Skaperen 7 369 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  Import Error Christian 3 670 Apr-17-2021, 11:27 PM
Last Post: bowlofred
  Folium import error kashif_flavio 2 679 Dec-07-2020, 08:58 AM
Last Post: bowlofred
  Import error Beingcode 0 776 Nov-20-2020, 02:57 AM
Last Post: Beingcode
Smile Import error with local file colt 1 540 Nov-08-2020, 07:56 AM
Last Post: Gribouillis
  switch from version 3.5.3 to 3.8.6 get import error python001 9 943 Oct-31-2020, 03:02 PM
Last Post: python001
  import yaml error for python3 maiya 4 3,582 Jul-15-2020, 06:07 PM
Last Post: Gribouillis
  Error while humansize module import. johnkgson 3 1,359 Apr-26-2020, 08:37 AM
Last Post: johnkgson
  Importing module from a package results in import error goghvv 2 802 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Python 2.7 Import error. Directory and filename conflict petcoo00 2 815 Feb-02-2020, 08:46 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020