我正在使用python进行时间序列分析。我阅读了从雅虎财经Yahoo Apple historical data
下载的csv文件 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
有人可以帮我吗?
答案 0 :(得分:0)
您似乎尚未将索引建立到pramlist
中。尽管您已完成Datetime
,但它仍保留为字符串索引。您应该将其转换为parse_dates
并通过DatetimeIndex
传递频率,
试试这个,
to_period