【发布时间】:2019-08-01 07:29:43
【问题描述】:
我正在使用 python 进行时间序列分析。我看了从雅虎财经下载的csv文件,Yahoo Apple historical data
aapl_df = pd.read_csv('AAPL.csv',
parse_dates=['Date'],
index_col='Date'
)
aapl_df.head()
# Simple Exponential Smoothing
adj_price = pd.Series(aapl_df['Adj Close'])
fit1 = SimpleExpSmoothing(adj_price).fit(smoothing_level=0.2,optimized=False)
fcast1 = fit1.forecast(12).rename(r'$\alpha=0.2$')
# plot
fcast1.plot(marker='o', color='blue', legend=True)
fit1.fittedvalues.plot(marker='o', color='blue')
当我使用 SimpleExpSmoothing 和 Holt 库时,
出现错误
/home/jupyterlab/conda/lib/python3.6/site-packages/statsmodels/tsa/base/tsa_model.py:225: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.
' ignored when e.g. forecasting.', ValueWarning)
/home/jupyterlab/conda/lib/python3.6/site-packages/statsmodels/tsa/base/tsa_model.py:531: ValueWarning: No supported index is available. Prediction results will be given with an integer index beginning at `start`.
ValueWarning)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-13-740724523405> in <module>
4 # plot
5 fcast1.plot(marker='o', color='blue', legend=True)
----> 6 fit1.fittedvalues.plot(marker='o', color='blue')
7
8
~/conda/lib/python3.6/site-packages/matplotlib/dates.py in tick_values(self, vmin, vmax)
1408 ymax = self.base.ge(vmax.year) * self.base.step
1409
-> 1410 ticks = [vmin.replace(year=ymin, **self.replaced)]
1411 while True:
1412 dt = ticks[-1]
ValueError: year 0 is out of range
有人可以帮我解决这个问题吗?
【问题讨论】:
-
分享一点数据,问题会更容易回答。
标签: python date error-handling time-series prediction