I am trying to run the following Statsmodels example from http://statsmodels.sourceforge.net/devel/examples/notebooks/generated/tsa_arma_0.html.
fig, ax = plt.subplots(figsize=(12, 8))
ax = dta.ix['1950':].plot(ax=ax)
fig = arma_mod30.plot_predict('1990', '2012', dynamic=True, ax=ax, plot_insample=False)
Running the code above gives the error message below. Even after upgrading to Statsmodels 6, I am getting the same error.
AttributeError Traceback (most recent call last)
<ipython-input-69-2a5da9c756f0> in <module>()
1 fig, ax = plt.subplots(figsize=(12, 8))
2 ax = dta.ix['1950':].plot(ax=ax)
----> 3 fig = arma_mod30.plot_predict('1990', '2012', dynamic=True, ax=ax, plot_insample=False)
C:\Anaconda\lib\site-packages\statsmodels\base\wrapper.pyc in __getattribute__(self, attr)
33 pass
34
---> 35 obj = getattr(results, attr)
36 data = results.model.data
37 how = self._wrap_attrs.get(attr)
AttributeError: 'ARMAResults' object has no attribute 'plot_predict'
Any suggestions?
This issue has been resolved after following the below comment. Thanks.
I've just encountered the same issue with statsmodels 0.13.2. After a bit of digging in their release notes I can see that the plotting functionality has been separated out. Instead of
arma_mod30.plot_predict(...)
try
from statsmodels.graphics.tsaplots import plot_predict
plot_predict(arma_mod30, ...)
Hope this helps
I also meet this issue for me the #pip install statsmodels==0.11.0 version get solved this promblem. I get this error after updating all the python packages. GL
Maybe it is the version of statsmodels made that happen. Try to check the version of statsmodels before upgrade the package to 0.6.1
>>> import statsmodels
>>> statsmodels.__version__
$ pip install statsmodels --upgrade
For more information, click this issue on statsmodels.github
Related
i am trying to learn machine learn through Python from W3School. I am trying to get mydecisiontree. PNG using PyDotPlus
I am using pip PyCharm professional 2020.3
the code is as follow:
import numpy as np
import matplotlib.pyplot as plt
import pandas
from sklearn import tree
import pydotplus
from sklearn.tree import DecisionTreeClassifier
import matplotlib.image as pltimg
df = pandas.read_csv("shows.csv")
d = {'UK' : 0,'USA' : 1, 'N' : 2}
df['Nationality'] = df['Nationality'].map(d)
d = {'YES' : 1, "NO" : 0}
df['Go'] = df['Go'].map(d)
features = ['Age', 'Experience', 'Rank', 'Nationality']
X = df[features]
y = df['Go']
dtree = DecisionTreeClassifier()
dtree = dtree.fit(X, y)
data = tree.export_graphviz(dtree, out_file=None, feature_names=features)
graph = pydotplus.graph_from_dot_data(data)
graph.write_png('mydecisiontree.png')
img=pltimg.imread('mydecisiontree.png')
img_plot = plt.imshow(img)
plt.show()
Although the PyCharm shows no error but when i run the code it cant make the PNG file and gives an error on the line:
graph.write_png('mydecisiontree.png')
It shows the following error:
File "direc.....\venv\lib\site-packages\pydotplus\graphviz.py", line 1960, in create
'GraphViz\'s executables not found')
pydotplus.graphviz.InvocationException: GraphViz's executables not found
I can't see the problem. How to solve this?
PyCharm doesn't show an error because your code doesn't contain any. The problem is in your environment. Have you installed GraphViz (using pip install graphviz) in the environment that you are using to run it?
Also see the answers here:
GraphViz not working when imported inside PydotPlus (GraphViz's executables not found)
Graphviz's executables are not found (Python 3.4)
I had that problem too,
I installed graphviz from: here
and it solved.
I keep getting this ImportError for just trying to set up a basic widget slider. Below is the input and error message.
import bokeh
from bokeh.io import output_notebook, show
import bokeh.models.widgets
from bokeh.models.widgets import Slider
slider = Slider(start = 0, end = 10 , value = 1, step=.1, title = 'do nothing')
show(slider)
ImportError Traceback (most recent call last)
<ipython-input-100-2c4894dccaf0> in <module>()
10 slider = Slider(start = 0, end = 10 , value = 1, step=.1, title = 'do nothing')
11
---> 12 show(slider)
11 frames
/usr/local/lib/python3.6/dist-packages/tornado/gen.py in <module>()
79 import types
80
---> 81 from tornado.concurrent import (
82 Future,
83 is_future,
ImportError: cannot import name 'future_set_exc_info'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
I do have bokeh package installed as well. Not sure what the issue is. Any help is appreciated.
In order to fix the error above, the tornado package must be up to date. To see what version works, simply look up the package itself to see what is the current version. Then input the following code at the beginning of your program to update the package.
# update tornado package
!pip install tornado==6.0.4
import tornado
I created a scatter plot on indian map in jupyter notebook but when i am trying to run the same code in my djnago app. It raises
ModuleNotFoundError: No module named 'mpl_toolkits.basemap'
Here's the code:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
# make up some data for scatter plot
lats = np.random.randint(6, 37, size=50)
lons = np.random.randint(68, 97, size=50)
fig = plt.gcf()
fig.set_size_inches(8, 6.5)
m = Basemap(projection='cyl', \
llcrnrlat=6., urcrnrlat=37., \
llcrnrlon=68., urcrnrlon=97., \
lat_ts=20, \
resolution='c',epsg=3857)
m.bluemarble(scale=1)
m.drawcoastlines(color='white', linewidth=0.2)
m.drawmapboundary(fill_color='#D3D3D3')
x, y = m(lons, lats)
plt.scatter(x, y, 10, marker='o', color='Red')
plt.show()
I am using the same conda interpreter in my django app. whats is the reason for this error ?
I use Anaconda under Win10. With a different OS or installation the solution may be different for you, but I can try to sketch the path.
You have to install Basemap. See here and here. For me conda install -c conda-forge basemap-data-hires did work.
When importing from mpl_toolkits.basemap import Basemap I got an error: KeyError: PROJ_LIB. Following the experiences here you must find a directory share with epsg inside. It is expected to be in the conda or the anaconda directory.
I did a search in my Anaconda3-dirctory and have found this path: "C:\Anaconda3\Library\share"
Then the following code did work for me (and your code gives a nice picture too :-) :
import os
proj_lib = "C:\Anaconda3\Library\share"
os.environ["PROJ_LIB"] = proj_lib
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
plt.figure(figsize=(8, 8))
m = Basemap(projection='ortho', resolution=None, lat_0=50, lon_0=-100)
m.bluemarble(scale=0.5);
I know this might be a very simple problem to solve, but I have been googling all day and cannot make it work. Please be patient with me - I just started working with Python.
I have a very simple code, that I can execute well in Jupyter, but it does not work in PyCharm:
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import pandas as pd
import numpy
y = pd.read_csv('data_all.csv')
df = y.iloc[:, 0:10]
print(df)
g = sns.PairGrid(df, hue='TP_PSP')
g = g.map(plt.scatter)
g = g.map_diag(plt.hist)
g = g.map_offdiag(plt.scatter)
g = g.add_legend()
I receive the following error:
Traceback (most recent call last):
File "C:/Users/lukas/PycharmProjects/untitled/mtth-matplot.py", line 18, in <module>
g = g.map_diag(plt.hist)
File "C:\Users\lukas\PycharmProjects\untitled\venv\lib\site-packages\seaborn\axisgrid.py", line 1399, in map_diag
func(data_k, label=label_k, color=color, **kwargs)
File "C:\Users\lukas\PycharmProjects\untitled\venv\lib\site-packages\matplotlib\pyplot.py", line 3132, in hist
stacked=stacked, normed=normed, data=data, **kwargs)
File "C:\Users\lukas\PycharmProjects\untitled\venv\lib\site-packages\matplotlib\__init__.py", line 1855, in inner
return func(ax, *args, **kwargs)
File "C:\Users\lukas\PycharmProjects\untitled\venv\lib\site-packages\matplotlib\axes\_axes.py", line 6713, in hist
labels = [six.text_type(lab) for lab in label]
TypeError: 'numpy.int64' object is not iterable
I have all packages installed and the interpreter works for "normal" python code. I am sorry posting such a trivial problem, but I cannot find a solution on the web that works for me. I am so grateful every hint to make it work.
Thanks in advance and best regards
LGR
This worked. I was facing a similar problem. Changed the Python Interpreter from 2.7 to 3.8 by clicking in the lower left portion of the Pycharm screen where it shows the interpreter being used. Code worked flawlessly.
Hi I am going to preface this with I could just be really dumb so don't overlook that, but suddenly when opening canopy today I wasn't able to run one of my typical scripts with the error AttributeError: 'module' object has no attribute ' version' when trying to load pandas. From what I can gather it seems when bumpy is called through pandas it fails. I checked my working directory for files named numpy.py to see if I idiotically named a file numpy but failed to find such a file. I also attempted to uninstall and reinstall both numpy and pandas from the package manager in canopy. Any suggestions?
%run "/Users/jim/Documents/ORAL-PAT-2.5-3.5plotly.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/jim/Documents/ORAL-PAT-2.5-3.5plotly.py in <module>()
1 #import the modules you need
----> 2 import pandas as pd
3 import numpy as np
4 import plotly.plotly as py
5 import plotly.tools as tls
/Users/jim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/__init__.py in <module>()
20
21 # numpy compat
---> 22 from pandas.compat.numpy_compat import *
23
24 try:
/Users/jim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/compat/numpy_compat.py in <module>()
13
14 # numpy versioning
---> 15 _np_version = np.version.short_version
16 _np_version_under1p8 = LooseVersion(_np_version) < '1.8'
17 _np_version_under1p9 = LooseVersion(_np_version) < '1.9'
AttributeError: 'module' object has no attribute 'version'
Just had the same problem after downgrading Pandas and upgrading again to fix another issue. This is just a hack, but you could try this:
Open ...pandas/compat/numpy_compat.py and replace np.version.short_version with np._np_version
Hope that helps!