您的位置:首页 > 产品设计 > UI/UE

愉快的学习就从翻译开始吧_Multi-Step or Sequence Forecasting

2018-06-30 18:02 459 查看

Multi-Step or Sequence Forecasting/

A different type of forecasting problem is using past observations to forecast a sequence of future observations.另一种类型的预测问题是使用过去的观测来预测未来观测的序列。
This may be called sequence forecasting or multi-step forecasting.这被称为序列预测或多步预测We can frame a time series for sequence forecasting by specifying another argument. For example, we could frame a forecast problem with an input sequence of 2 past observations to forecast 2 future observations as follows:我们可以通过指定另一个参数来构建序列预测的时间序列。 例如,我们可以用2个过去的观测值的输入序列来构造预测问题,以预测2个未来的观测值,如下所示:

1data = series_to_supervised(values, 2, 2)

The complete example is listed below:from pandas import DataFrame from pandas import concat def series_to_supervised(data, n_in=1, n_out=1, dropnan=True): """ Frame a time series as a supervised learning dataset. Arguments: data: Sequence of observations as a list or NumPy array. n_in: Number of lag observations as input (X). n_out: Number of observations as output (y). dropnan: Boolean whether or not to drop rows with NaN values. Returns: Pandas DataFrame of series framed for supervised learning. """ n_vars = 1 if type(data) is list else data.shape[1] df = DataFrame(data) cols, names = list(), list() # input sequence (t-n, ... t-1) for i in range(n_in, 0, -1): cols.append(df.shift(i)) names += [('var%d(t-%d)' % (j + 1, i)) for j in range(n_vars)] # forecast sequence (t, t+1, ... t+n) for i in range(0, n_out): cols.append(df.shift(-i)) if i == 0: names += [('var%d(t)' % (j + 1)) for j in range(n_vars)] else: names += [('var%d(t+%d)' % (j + 1, i)) for j in range(n_vars)] # put it all together agg = concat(cols, axis=1) agg.columns = names # drop rows with NaN values if dropnan: agg.dropna(inplace=True) return agg values = [x for x in range(10)] data = series_to_supervised(values,2,2) print(data)
Running the example shows the differentiation of input (t-n) and output (t+n) variables with the current observation (t) considered an output.运行该示例显示输入(t-n)和输出(t + n)变量与当前观察值(t)被视为输出的差异。

12345678   var1(t-2)  var1(t-1)  var1(t)  var1(t+1)2        0.0        1.0        2        3.03        1.0        2.0        3        4.04        2.0        3.0        4        5.05        3.0        4.0        5        6.06        4.0        5.0        6        7.07        5.0        6.0        7        8.08        6.0        7.0        8        9.0
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: