how to import sklearn.impute on jupyter NoteBook? - python

have problem importing impute module from sklearn in jupyter :
from sklearn.impute import SimpleImpute
I've tried every solution till now,
installing the latest version of both sklearn(0.23.1) and jupyter(6.0.3) notebook
but still have the same error
ModuleNotFoundError: No module named 'sklearn.impute'
I've already tried the same codes on IDLE and there's no problem
the problem is on jupyter
How can I fix this problem?

Run below command in jupyter-notebook and verify if scikit-learn of version 0.23 is in the list. If it is not in the list, then it means your IDLE and jupyter-notebook are using different python installations. (since it is working in IDLE)
!pip list
If it is missing in the list, then install it directly from jupyter-notebook using
!pip install --upgrade scikit-learn

Related

Cannot import packes from within conda virtual environment

I am using Python 3.8 on a Ubuntu 20.04 computer. So far, I had no problem importing packages from either Spyder of Jupyter.
I have created a conda virtual environment called theory using Python 3.6, as confirmed by running python --version from within this conda environment.
conda list reveals that numpy is installed:
numpy 1.19.4 pypi_0 pypi
Opening a Python interactive session from the terminal and importing numpy in there works like a charm.
However, when trying to import numpy from within Spyder, I am getting a "Module Not Found" error:
ModuleNotFoundError: No module named 'numpy'
Here is what I tried to fix this issue:
I tried uninstalling and reinstalling numpy using pip install numpy (and pip3 install numpy).
I tried updating conda following the answer provided in this GitHub post: conda update --prefix /home/sheldon/anaconda3 anaconda .
I tried specifying the path to the numpy package in the PYTHONPATH manager directly in Spyder, pointing to /home/sheldon/anaconda3/envs/
What am I doing wrong here?
EDIT: I checked that Numpy 1.9.4. actually supports Python 3.6
EDIT: Just recreated a new Python 3.6 environment from scratch and I can import numpy just fine...
can you please try this :
uninstall numpy with pip uninstall
and re install it with
conda install numpy
Not pip install..

Statsmodels import problems

I'm having trouble importing statsmodels into my Jupyter Notebook where I'm running Python 3.8.3
My error: ModuleNotFoundError: No module named 'statsmodels'
Things I've tried:
pip install statsmodels
conda install statsmodels
pip install git+https://github.com/statsmodels/statsmodels
This is all done in my virtual environment, which is activated in the jupyter notebook I'm attempting the import in.
I've also attempted importing using import statsmodels.api as sm, import statsmodels.robust as rb as I saw some SO posts suggesting it, but I still get the same error.
When I type !conda list on my terminal, I see statsmodels in the available packages, yet I still can't import it.
Running out of ideas here, any help is appreciated

Matplotlib in Tensorflow Jupyter Notebook

In Anaconda Navigator, I switched to running applications on tensorflow and installed jupyter 5.6.0. I then open up a Python3 notebook. I then import tensorflow, keras and numpy without issue. Then when I try to import matplotlib, the notebook says ImportError: No module named 'matplotlib'.
I tried running the following command in my anaconda prompt in both base and after activating tensorflow: pip3 install matplotlib
And it says:
(tensorflow) C:\Users\danie>pip3 install matplotlib
Requirement already satisfied
for 7 different lines. What am I doing wrong?
Add import sys and sys.executable to the top of your notebook, then run it. This shows you the directory of the running kernel. With this information, from a new command-line (not a Python console) run C:\path\to\python.exe -m pip install matplotlib
! pip install matplotlib ,worked perfect for me in the tensorflow environment (Jupyter)

python module 'pandas' has no attribute 'plotting'

I am a beginner of Python. I follow the machine learning course of Intel. And I encounter some troubles in coding. I run the code below in Jupyter and it raises an AttributeError.
import pandas as pd
step_data = [3620, 7891, 9761,3907, 4338, 5373]
step_counts = pd.Series(step_data,name='steps')
print(step_counts)
AttributeError: module 'pandas' has no attribute 'plotting'
In your terminal type
pip install plotting.
Update your pandas version using following command
pip install --upgrade pandas
If you want to execute pip command directly in Jupyter notebook, run the following:
import sys
!{sys.executable} -m pip install --upgrade pandas
The above code makes sure that the package is installed for the same version of python installed with Jupyter notebook.
In some situations the below command also works:
!pip install --upgrade pandas
Updating pandas usually corrects this error. Hence update your version of pandas and the error should be solved. Additionally, your code snippet does work.

Xgboost package on mac

I am trying to use Xgboost but facing problems in installation.
i am using mac and I use python notebook jupyter for the same. I opened the command line and used pip install xgboost and it got installed successfully but when I try to use it in my code by writing import xgboost as xg then I get ImportError: No module named xgboost
Can anyone help me?
It may come from the fact that you have two (or more) python environments. A hacky solution is to install it within Jupyter Notebook (note the '!'):
!pip install xgboost

Categories

Resources