小编Pet*_*sen的帖子

如何绘制单个数据点?

我有以下代码来绘制一条线和一个点:

df = pd.DataFrame({'x': [1, 2, 3], 'y': [3, 4, 6]})
point = pd.DataFrame({'x': [2], 'y': [5]})
ax = df.plot(x='x', y='y', label='line')
ax = point.plot(x='x', y='y', ax=ax, style='r-', label='point')
Run Code Online (Sandbox Code Playgroud)

如何显示单个数据点?

绘制线条,没有任何意义

python plot matplotlib pandas

23
推荐指数
3
解决办法
6万
查看次数

ARMA.predict的预测间隔

时间序列(print arma_mod.summary())的ARMA预测摘要显示了一些有关置信区间的数字。可以在显示预测值的图中将这些数字用作预测间隔吗?

ax = indexed_df.ix[:].plot(figsize=(12,8))
ax = predict_price.plot(ax=ax, style='rx', label='Dynamic Prediction');
ax.legend(); 
Run Code Online (Sandbox Code Playgroud)

我猜代码:

from statsmodels.sandbox.regression.predstd import wls_prediction_std
prstd, iv_l, iv_u = wls_prediction_std(results)
Run Code Online (Sandbox Code Playgroud)

在这里找到:模型预测的置信区间

...不适用于OLS,而不适用于ARMA预测。我还检查了github,但没有发现任何可能与时间序列预测有关的新内容。

(我想做出预测需要一定的预测间隔,特别是在样本超标的情况下。)

帮助表示赞赏。

python time-series confidence-interval forecasting autoregressive-models

4
推荐指数
1
解决办法
3569
查看次数

用于样本外预测的 ARMA.predict 不适用于浮点数?

在我为样本内分析开发了我的小 ARMAX 预测模型后,我想预测一些样本外的数据。

我用于预测计算的时间序列从 2013-01-01 开始,到 2013-12-31 结束!

这是我正在使用的数据:

hr = np.loadtxt("Data_2013_17.txt")
index = date_range(start='2013-1-1', end='2013-12-31', freq='D')
df = pd.DataFrame(hr, index=index)
holidays = ['2013-1-1', '2013-3-29', '2013-4-1', '2013-5-1', '2013-5-9', '2013-5-20', '2013-10-3', '2013-12-25', '2013-12-26']
# holidays for all Bundesländer 
idx = df.asfreq('B').index - DatetimeIndex(holidays)
indexed_df = df.reindex(idx)
# indexed_df = df.asfreq('B') (includes holidays)
# 'D'=day
#'B'=business day
# W@MON=shows only mondays

# external variable  
hr_ = np.loadtxt("Data_2_2013.txt")
index = date_range(start='2013-1-1', end='2013-12-31', freq='D')
df = pd.DataFrame(hr_, index=index)
idx2 = df.asfreq('B').index - DatetimeIndex(holidays)
external_df1 …
Run Code Online (Sandbox Code Playgroud)

python time-series forecasting statsmodels

3
推荐指数
1
解决办法
1万
查看次数

ConvergenceWarning:最大似然减慢内核运行时间?

我使用非常nicht 的代码对象arma_order_select_ic来找到最低的信息标准来选择 p- 和 q 值。

我不确定我是否做得对,或者代码是否只是偶然发现了一些错误......

在:

y = indexed_df
res = arma_order_select_ic(y, max_ar=7, max_ma=7, ic=['aic', 'bic', 'hqic'], trend='c', fit_kw=dict(method='css'))
print res
print ('AIC-order: {}' .format(res.aic_min_order))
print ('BIC-order: {}' .format(res.bic_min_order))
print ('HQIC-order: {}' .format(res.hqic_min_order)) 
Run Code Online (Sandbox Code Playgroud)

出去:

/Applications/anaconda/lib/python2.7/site-packages/statsmodels-0.6.1-py2.7-macosx-10.5-x86_64.egg/statsmodels/base/model.py:466: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
  "Check mle_retvals", ConvergenceWarning)
Run Code Online (Sandbox Code Playgroud)

另外:它打印出三个矩阵样式列表(每个 IC 一个矩阵)和最终推荐:

AIC-order: (7, 5)
BIC-order: (7, 0)
HQIC-order: (7, 0)
Run Code Online (Sandbox Code Playgroud)

所以,整件事似乎都奏效了。

问题是,每次计算都会打印警告,大约需要 30-60 秒,即它非常慢!

我检查了相关的源代码(statsmodels/base/model.py)以及如何跳过打印 CovergenceWarning:

   #TODO: hardcode scale?
        if isinstance(retvals, dict):
            mlefit.mle_retvals = retvals
            if warn_convergence …
Run Code Online (Sandbox Code Playgroud)

python time-series forecasting statsmodels

2
推荐指数
1
解决办法
1万
查看次数

更改DataFrame中的索引数量?

我试图更改以下代码的输出:

import numpy as np
import pandas as pd
from pandas import Series, DataFrame, Panel, bdate_range, DatetimeIndex, date_range
from pandas.tseries.holiday import get_calendar
from datetime import datetime, timedelta
import pytz as pytz
from pytz import timezone

start =  datetime(2013, 1, 1)

hr1 = np.loadtxt("Spot_2013_Hour1.txt")

index = date_range(start, end = '2013-12-31', freq='B')
Allhrs = Series(index)
Allhrs = DataFrame({'hr1': hr1})
df = Allhrs
indexed_df = df.set_index(index)
print indexed_df
Run Code Online (Sandbox Code Playgroud)

错误:

  File "<ipython-input-61-c7890d8ccb07>", line 17, in <module>
    indexed_df = df.set_index(index)

  File "/Applications/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 2390, in …
Run Code Online (Sandbox Code Playgroud)

python datetime calendar dataframe pandas

0
推荐指数
1
解决办法
2263
查看次数