"load_breast_cancer" could not be loaded for iPython notebook - python

I tried to run from sklearn.datasets import load_breast_cancer on my iPython notebook (Python 2, Jupyter, Dato), and got the importError:
ImportError Traceback (most recent call last)
<ipython-input-12-09d44d891711> in <module>()
----> 1 from sklearn.datasets import load_breast_cancer
ImportError: cannot import name load_breast_cancer
But it works fine if I run others, e.g. from sklearn.datasets import load_diabetes, from sklearn.datasets import load_boston.
So how to import the load_breast_cancer? Thank you.

try pip install --upgrade sklearn
if you don't know where your kernel is running (if updating your machine didn't work, it seems like it is hosted somewhere else), run !pip install --upgrade sklearn in a notebook cell.

Related

ModuleNotFoundError: No module named 'category_encoders'

I tried few way to install category encoders and it never works.
Here are the ways I did, each installation shows success. anyone has any suggestion? Thanks
pip install --upgrade category_encoders
conda install -c conda-forge category_encoders
from category_encoders.target_encoder import TargetEncoder
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [17], in <cell line: 1>()
----> 1 from category_encoders.target_encoder import TargetEncoder
ModuleNotFoundError: No module named 'category_encoders'
make sure you are using the same python version, when you install the library and you run it.
my suggestion is create new virtual environment and activate then install all library that needed, then run your app from there.
try this
from sklearn.preprocessing import OneHotEncoder

Import error: No module name sklearn.external.six

I am currently using anaconda 4.8.3 and want to display a figure of decision tree and i have install graphviz and pydotplus library in anaconda instead of this i am getting error 'ModuleNotFoundError: No module named 'sklearn.externals.six' .this is my code:
from sklearn.tree import DecisionTreeClassifier
from IPython.display import Image
from sklearn.externals.six import StringIO
from sklearn.tree import export_graphviz
import pydot
features = list(df.columns[1:])
features
This is my error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-19-0b3416ce7fda> in <module>
1 from IPython.display import Image
---> 2 from sklearn.externals.six import StringIO
3 from sklearn.tree import export_graphviz
4 import pydot
5 ModuleNotFoundError: No module named 'sklearn.externals.six'
You can import StringIO from module six directly, no need to downgrade scikit.
from six import StringIO
Module sklearn.externals.six was removed in the scikit-learn version 0.23. To use it you have to downgrade to version 0.22. For that, you can do -
In jupyter notebook try :!pip install --upgrade scikit-learn==0.22
In terminal: pip install --upgrade scikit-learn==0.22

sklearn module not found in anaconda

I've been trying to import sklearn but it says that the module is not found.
my python, numpy, scipy and scikit versions are as follows as show in the conda list:
numpy 1.14.3 py36h9fa60d3_1
python 3.6.5 h0c2934d_0
scipy 1.1.0 py36h672f292_0
scikit-learn 0.19.1 py36h53aea1b_0
the error while trying to import sklearn is:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-f2461ba6e1e9> in <module>()
----> 1 from sklearn.family import model
ModuleNotFoundError: No module named 'sklearn.family'
I tried using
conda update scikit-learn
conda install scikit-learn
but I get the following results
All requested packages already installed.
how do I import sklearn then?
Although there is not skleran module, from sklearn import ... works well in PyCharm:
from sklearn.utils import resample
Try doing
conda install -c anaconda pip
pip install sklearn
AFAIK, there's no sklearn.family module. Have you tried importing other modules?
Say,
from sklearn.model_selection import TimeSeriesSplit
Does that work for you?

Cannot import statsmodels.formula.api

Whenever i am trying to import statsmodels.formula.api as smf i get the following error.
import statsmodels.formula.api as smf
Traceback (most recent call last):
File "<ipython-input-257-268d740a5877>", line 1, in <module>
import statsmodels.formula.api as smf
File "C:\Users\ldresl\Anaconda3\lib\site-
packages\statsmodels\formula\__init__.py", line 1, in <module>
from statsmodels import PytestTester
ImportError: cannot import name 'PytestTester'
You will have to update the package pytest and restart your kernel:
pip install pytest --upgrade
I had this problem importing statsmodels in a Jupyter notebook (Anaconda distribution). If you run on the same set-up, you can update a package in Anaconda like so:
conda update pytest
Do not forget to restart the kernel in the top navigation of your notebook afterwards. Hope that helps.
Worked for me,
pip install statsmodels --upgrade
pip install pytest --upgrade
Restart Kernel

Python statsmodels and simple exponential smoothing in Jupyter and PyCharm

I am new to python, and trying to run this example in Jupyter notebook. Whenever I run following
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.api import SimpleExpSmoothing
It gives me following error
ImportError Traceback (most recent call last)
<ipython-input-5-a15788c08ca7> in <module>()
3 import pandas as pd
4 import matplotlib.pyplot as plt
----> 5 from statsmodels.tsa.api import SimpleExpSmoothing
ImportError: cannot import name 'SimpleExpSmoothing'
Although, I have installed statsmodels (0.8.0) by
pip install statsmodels
like other packages (numpy, pandas etc.). I checked on git, api file contains this method but my api file (obtained through pip) doesn't have this method. Maybe I am not getting the git version (seems latest one) through pip? I am working in windows and I also tried on mac OSX, and result is same. I tried to do a copy/paste attempt for missing files/code in files from git (not a good way) but it doesn't help. I would appreciate your suggestions here.
EDIT
So the solution for Jupyter (thanks to #user333700) is to install master branch directly from git by
pip install git+https://github.com/statsmodels/statsmodels.git
I am extending my question for PyCharm, how can I add a git package within PyCharm? This link does not help.
For future reference another solution which worked for me is to pip install the latest version directly:
pip install statsmodels==0.9.0rc1

Categories

Resources