Forecasting a subset of time-series features

186 Views Asked by At

I've followed the TensorFlow tutorial on time series forecasting:

The tutorial demonstrates how to forecast a single feature or all features for a single time-step using a residual wrapper with a LSTM. How do I predict a subset (2) of features?

The code for predicting a single feature:

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)
]))

When I try predicting both T (degC) and p (mbar):

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)
]))

I get an error:

ValueError: Dimensions must be equal, but are 19 and 2 for '{{node residual_wrapper/add}} = AddV2[T=DT_FLOAT](IteratorGetNext, residual_wrapper/sequential/dense/BiasAdd)' with input shapes: [?,24,19], [?,24,2].
0

There are 0 best solutions below