I'm not able to import the following modules in an ipython notebook:
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
The following error pops up
ImportError: cannot import name PolynomialFeatures
The same error also appears for make_pipeline.
I'm a newbie in scikit-learn, please help out.
I'm using the miniconda installation of python and the version number for scikit-learn is 0.14.1.
Polynomial Features is included for next version of scikit-learn and is not available in 0.14.1. Please update to 0.15-git if you want to use it. The same holds for make pipeline.
To get the bleeding edge version:
git clone git://github.com/scikit-learn/scikit-learn.git
python setup.py build_ext --inplace
Please read: http://scikit-learn.org/stable/developers/index.html#git-repo
You have to check your current version of scikit:
import sklearn
print sklearn.__version__
if it is less than 0.15.0, then you have to upgrade it. In addition to an excellent answer of Abhishek, you can follow official installation process (which is described for various OS).
If you are using pyCharm, it can be done even simpler: File -> Settings -> Project Interpreter and then select your package and click upgrade
(I selected another one, be cause my scikitlearn is the newest)
Related
As I said in the title, I cannot import sparkdl module into databricks.
I followed step by step this official tutorial sparkdl tutorial but when I simply put some code like:
from sparkdl import readImages
I get an error that says I cannot import readImages from sparkdl, the same for other classes such DeepImageFeaturizer.
I checked and It seems there is some sort of problem with the versions of keras,tensorflow,sparkdl,h5py and the maven library spark-deep-learning so I'm looking for a stable combination beetween them.
Taking into account that from Databricks I can only install tensorflow from 2.5.0 up to newer version.
With the following versions:
tensorflow v 2.5.0, keras 2.2.4, 1.4.0-spark-deep-learning,h5py v 3.7.0
I Got the following error while importing DeepImageFeaturizer
from sparkdl import DeepImageFeaturizer ImportError: cannot import name 'resnet50' from 'keras.applications' (/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/keras/applications/__init__.py)
Any help or suggestion will be really appreciated
I am a beginner and I just started with machine learning. I am trying to import classes like imputer from sklearn but i am unable to do it.
from sklearn.preprocessing import Imputer,LabelEncoder,OneHotEncoder,StandardScaler
ImportError: cannot import name 'version' from
'sklearn.externals.joblib'
(C:\ProgramData\Anaconda3\lib\site-packages\sklearn\externals\joblib__init__.py)
I had the same problem.
I have replaced
from sklearn.externals import joblib
with
import joblib
and it works fine in Python 3.7.2
I believe there was an update on Scikit-learn that render that import unusable.
I had my local installation to be version 0.20.3 and this import is pefectly working. But on my server I have installation 0.23.1 and this error pop up. Something must be chaging in the new version.
For my case, use import joblib fix the problem. In your case it seems more complicated. This sounds very much likeky to be caused if you have more than one Scikit-learn version installed on your system. You need to uninstall all of them and do a clean install of sklearn.
The problem sometimes happens due to the version. This may help:
If you has written like this
from sklearn.externals import joblib
Modify it as this:
import joblib
Try
python -m pip install sklearn --upgrade
and
python -m pip install joblib --upgrade
and then, use this :
import joblib
Good luck.
import joblib
This works for me. Actually I was having that kinda challenge
I'm relatively new to python, so please excuse my ignorance on what could be a very easy fix. I am running python 3.6 through the Rodeo IDE, and it has been great, as it is similar to R-Studio (which I am very familiar with). As an aspiring data scientist, I am trying to learn how to fit regression and time series models to data, and all of the tutorials that I have found all say that I need various packages, all of which should be included in the Anaconda library. After downloading and re-downloading Python, Rodeo, and Anaconda, and trying various online fixes, I have been unable to successfully load the scikit-learn and the statsmodels modules.
#here is everything I have tried.
#using pip
! pip install 'statsmodels'
! pip install 'scikit-learn'
! pip install 'sklearn'
I don't get any errors here, and to be honest I'm kind of confused as to what this actually does, but I have seen many people online always suggest that this is a big problem when trying to import modules.
#using import
import sklearn
import statsmodels
from sklearn import datasets
import statsmodels.api as sm
all of the above give me the same error:
import statsmodels.api as sm
ImportError: No module named 'statsmodels'
ImportError: Traceback (most recent call last)
ipython-input-184-6030a6549dc0 in module()
----> 1 import statsmodels.api as sm
ImportError: No module named 'statsmodels'
I have tried to set my working directory to the Anaconda 3 file that has all of the packages and rerunning the above code with no success.
I'm thinking that the most likely problem has to do with my inexperience, and it is probably a simple fix. Is it possible that the IDE is bad or anaconda just doesn't like me?
So keeping all of the above in mind, the question is, how can I import these modules successfully so that I can access their functionality?
Option 1:
After installing packages with pip, try closing and reopening your IDE/Jupyter Notebook and try again.
This is a known bug that Jake VanderPlas outlined here
Option 2:
Don't put quotations around your pip messages.
!pip install -U statsmodels
!pip install scikit-learn
Option 3:
Also are you using Anaconda? If you are, you should already have scikit-learn. If you are trying inside Rodeo, I think you need to set your path inside Rodeo. Open Rodeo and set the Python Path to your fresh anaconda. See here
I am trying to import matplotlib.finance module in python so that I can make a Candlestick OCHL graph. My matplotlib.pyplot version is 2.00. I've tried to import it using the following commands:
import matplotlib.finance
from matplotlib.finance import candlestick_ohlc
I get this error:
warnings.warn(message, mplDeprecation, stacklevel=1)
MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead.
Then instead of using the above lines in python I tried using the following line:
import mpl_finance
I get this error:
ImportError: No module named 'mpl_finance'
What should I do to import candlestick from matplotlib.pyplot?
I've stopped using mpl_finance (and plotly) since they are too slow. Instead I've written an optimized finance plotting library, finplot, which I use to backtest up to 107 candles.
Here's a small example:
import yfinance as yf
import finplot as fplt
df = yf.download('SPY',start='2018-01-01', end = '2020-04-29')
fplt.candlestick_ochl(df[['Open','Close','High','Low']])
fplt.plot(df.Close.rolling(50).mean())
fplt.plot(df.Close.rolling(200).mean())
fplt.show()
Examples included show SMA, EMA, Bollinger bands, Accumulation/Distribution, Heikin Ashi, on balance volume, RSI, TD sequential, MACD, scatter plot indicators, heat maps, histograms, real-time updating charts and interactive measurements; all with sensible defaults ready for use.
I do dogfooding every day, drop me a note or a pull request if there is something you want. Hope you take it for a spin!
In 2020, one can now pip install mplfinance
What this warning tells you is that the finance module will be removed at some point.
At the moment you don't need to worry about this warning. It will only affect you when you update to a yet to be released version 2.2 of matplotlib, in which case you'll need to change your imports.
If you already want to be compatible with future versions now, you can download the mpl_finance module from
https://github.com/matplotlib/mpl_finance .
After having downloaded the files, you may install in the usual way,
python setup.py install
Alternatively you may try installing through pip,
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
The reason for this is that the people at matplotlib want to keep their code clean and not maintain a specialized sidepackage like this in the main code. They probably also do not want to maintain the package and spend resources on it, which can be better used in the core development.
Since mpl_finace is not on pip now, you may also want to use following command to install mpl_finance by pip:
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
mpl_finance is no longer part of matplotlib. Install the module directly from gitHub via pip
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
and import it with
from mpl_finance import candlestick_ohlc
Then it works the same as before.
There is a new version of matplotlib finance, with documentation, here:
https://pypi.org/project/mplfinance/
https://github.com/matplotlib/mplfinance
Install with: pip install --upgrade mplfinance
Or with: conda install -c conda-forge mplfinance
NOTE: The package name no longer has the dash or underscore:
It is now mplfinance (not mpl-finance, nor mpl_finance)
I'm working on google colab , i got the same problem . then what i did -for python3.6
import mpl_finance
from mpl_finance import candlestick_ohlc
Plotly.py, a web-browser based, interactive plotting module has finance plotting functions https://plot.ly/python/candlestick-charts/. And it is maintained.
Simply use pip install mpl_finance for Windows or pip3 install mpl_finance for Linux/Unix for installation.
Then use from mpl_finance import candlestick_ohlc to call the library in the Jupyter notebook!
Replace from matplotlib.finance import candlestick_ohlc with from mplfinance.original_flavor import candlestick_ohlc , That should work.
I am trying to import matplotlib.finance module in python so that I can make a Candlestick OCHL graph. My matplotlib.pyplot version is 2.00. I've tried to import it using the following commands:
import matplotlib.finance
from matplotlib.finance import candlestick_ohlc
I get this error:
warnings.warn(message, mplDeprecation, stacklevel=1)
MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead.
Then instead of using the above lines in python I tried using the following line:
import mpl_finance
I get this error:
ImportError: No module named 'mpl_finance'
What should I do to import candlestick from matplotlib.pyplot?
I've stopped using mpl_finance (and plotly) since they are too slow. Instead I've written an optimized finance plotting library, finplot, which I use to backtest up to 107 candles.
Here's a small example:
import yfinance as yf
import finplot as fplt
df = yf.download('SPY',start='2018-01-01', end = '2020-04-29')
fplt.candlestick_ochl(df[['Open','Close','High','Low']])
fplt.plot(df.Close.rolling(50).mean())
fplt.plot(df.Close.rolling(200).mean())
fplt.show()
Examples included show SMA, EMA, Bollinger bands, Accumulation/Distribution, Heikin Ashi, on balance volume, RSI, TD sequential, MACD, scatter plot indicators, heat maps, histograms, real-time updating charts and interactive measurements; all with sensible defaults ready for use.
I do dogfooding every day, drop me a note or a pull request if there is something you want. Hope you take it for a spin!
In 2020, one can now pip install mplfinance
What this warning tells you is that the finance module will be removed at some point.
At the moment you don't need to worry about this warning. It will only affect you when you update to a yet to be released version 2.2 of matplotlib, in which case you'll need to change your imports.
If you already want to be compatible with future versions now, you can download the mpl_finance module from
https://github.com/matplotlib/mpl_finance .
After having downloaded the files, you may install in the usual way,
python setup.py install
Alternatively you may try installing through pip,
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
The reason for this is that the people at matplotlib want to keep their code clean and not maintain a specialized sidepackage like this in the main code. They probably also do not want to maintain the package and spend resources on it, which can be better used in the core development.
Since mpl_finace is not on pip now, you may also want to use following command to install mpl_finance by pip:
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
mpl_finance is no longer part of matplotlib. Install the module directly from gitHub via pip
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
and import it with
from mpl_finance import candlestick_ohlc
Then it works the same as before.
There is a new version of matplotlib finance, with documentation, here:
https://pypi.org/project/mplfinance/
https://github.com/matplotlib/mplfinance
Install with: pip install --upgrade mplfinance
Or with: conda install -c conda-forge mplfinance
NOTE: The package name no longer has the dash or underscore:
It is now mplfinance (not mpl-finance, nor mpl_finance)
I'm working on google colab , i got the same problem . then what i did -for python3.6
import mpl_finance
from mpl_finance import candlestick_ohlc
Plotly.py, a web-browser based, interactive plotting module has finance plotting functions https://plot.ly/python/candlestick-charts/. And it is maintained.
Simply use pip install mpl_finance for Windows or pip3 install mpl_finance for Linux/Unix for installation.
Then use from mpl_finance import candlestick_ohlc to call the library in the Jupyter notebook!
Replace from matplotlib.finance import candlestick_ohlc with from mplfinance.original_flavor import candlestick_ohlc , That should work.