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

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个未来的观测值,如下所示:

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)

运行该示例显示输入(t-n)和输出(t + n)变量与当前观察值(t)被视为输出的差异。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
There are several ways to perform LSTM multi-step prediction in Matlab. One possible approach is as follows: 1. Load and preprocess the data: Load the dataset and preprocess it by normalizing the data, dividing it into training and testing sets, and creating input-output pairs for the LSTM model. 2. Define the LSTM model: Create a Sequential model in Matlab and add LSTM layers with appropriate input and output sizes. You may also add other layers such as Dropout or Dense layers to improve the model's performance. 3. Train the LSTM model: Train the LSTM model on the training data using the fit function in Matlab. You can specify the number of epochs, batch size, and other training parameters. 4. Make predictions: Use the predict function in Matlab to make predictions on the test data. You can use the output from the previous time step as input for the next prediction, creating a sequence of predictions. 5. Evaluate the model: Calculate the mean squared error or other metrics to evaluate the performance of the LSTM model. Here is some sample code for LSTM multi-step prediction in Matlab: % Load and preprocess the data data = load('data.mat'); data = normalize(data); [trainData, testData] = splitData(data, 0.8); [trainX, trainY] = createInputOutputPairs(trainData, seqLength, numFeatures); [testX, testY] = createInputOutputPairs(testData, seqLength, numFeatures); % Define the LSTM model model = createLSTMModel(seqLength, numFeatures, numOutputs, numHiddenUnits); % Train the LSTM model options = trainingOptions('adam', 'MaxEpochs', numEpochs, 'MiniBatchSize', miniBatchSize); trainedModel = trainModel(model, trainX, trainY, options); % Make predictions numSteps = size(testX, 2) / numOutputs; predictions = []; for i = 1:numSteps idx = (i-1)*numOutputs+1 : i*numOutputs; if i == 1 input = testX(:, idx, :); else input = cat(2, output, testX(:, idx(end), :)); end output = predict(trainedModel, input); predictions = cat(2, predictions, output); end % Evaluate the model mse = evaluateModel(predictions, testY);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值