Tensorflow 预测时间序列特征的子集

Tensorflow 预测时间序列特征的子集,tensorflow,machine-learning,time-series,forecasting,tensorflow2.x,Tensorflow,Machine Learning,Time Series,Forecasting,Tensorflow2.x,我遵循了关于时间序列预测的TensorFlow教程: 本教程演示了如何使用带有LSTM的剩余包装预测单个功能或单个时间步的所有功能。如何预测特征的子集(2) 用于预测单个特征的代码: wide_window = WindowGenerator( input_width=24, label_width=24, shift=1, label_columns=['T (degC)']) for example_inputs, example_labels in wide_win

我遵循了关于时间序列预测的TensorFlow教程:

本教程演示了如何使用带有LSTM的剩余包装预测单个功能或单个时间步的所有功能。如何预测特征的子集(2)

用于预测单个特征的代码:

wide_window = WindowGenerator(
    input_width=24, label_width=24, shift=1,
    label_columns=['T (degC)'])

for example_inputs, example_labels in wide_window.train.take(1):
  print(f'\nInputs shape (batch, time, features): {example_inputs.shape}')
  print(f'Labels shape (batch, time, features): {example_labels.shape}\n')

class ResidualWrapper(tf.keras.Model):
  def __init__(self, model):
    super().__init__()
    self.model = model

  def call(self, inputs, *args, **kwargs):
    delta = self.model(inputs, *args, **kwargs)

    # The prediction for each timestep is the input
    # from the previous time step plus the delta
    # calculated by the model.
    return inputs + delta

residual_lstm = ResidualWrapper(
    tf.keras.Sequential([
    # Shape [batch, time, features] => [batch, time, lstm_units]
    tf.keras.layers.LSTM(32, return_sequences=True),
    # Shape => [batch, time, features]
    tf.keras.layers.Dense(
        units=1,
        # The predicted deltas should start small
        # So initialize the output layer with zeros
        kernel_initializer=tf.initializers.zeros)
]))

当我尝试预测T(degC)和p(mbar)时:

我得到一个错误:

ValueError:维度必须相等,但对于输入形状为“{node residential_wrapper/add}}=AddV2[T=DT_FLOAT](IteratorGetNext,residential_wrapper/sequential/dense/BiasAdd)的“{node residential_wrapper/add}”而言,维度为19和2:[?,24,19],?,24,2]。
wide_window = WindowGenerator(
    input_width=24, label_width=24, shift=1,
    label_columns=['T (degC)','p (mbar)'])

residual_lstm = ResidualWrapper(
    tf.keras.Sequential([
    # Shape [batch, time, features] => [batch, time, lstm_units]
    tf.keras.layers.LSTM(32, return_sequences=True),
    # Shape => [batch, time, features]
    tf.keras.layers.Dense(
        units=2,
        # The predicted deltas should start small
        # So initialize the output layer with zeros
        kernel_initializer=tf.initializers.zeros)
]))