0
$\begingroup$

I have a single layer LSTM model with 300 time series which try to predict the next value for one time series, based on past 12 values of the 300 time series. 56 is the number of slices of length 12 in the training set

Training input -> output shape:

  • 56,12,300 -> 56,

1 Prediction input -> output shape:

  • 1,12,300 -> 1,

The problem comes with the scale of the values. I'm trying to normalize the values, but I don't know if I should scale only the train dataset or all the dataset. And how to denormalize a single scalar value (predicted output)

$\endgroup$

1 Answer 1

0
$\begingroup$

You should normalize after the x, y split. No need to scale the target.

Try on this line
I have used 5K samples. 56 might not be enough

sample = 5000
seq_len = 12
features = 300

data = np.arange(0,sample*seq_len*features+1,1) #data.shape

x = data[:-1].reshape((sample,seq_len,features))
y = data[seq_len*features::seq_len*features] #.shape, y.shape

model = Sequential()

model.add(layers.GRU(100, return_sequences=True, input_shape=(seq_len,features)))
model.add(layers.GRU(100, return_sequences=False))
model.add(layers.Dense(1000, activation='relu'))
model.add(layers.Dense(1, activation='linear'))

# Scale
min,max = x.min(axis=0), x.max(axis=0)
x = (x - min)/(max-min)

model.compile(optimizer='adam', loss='mse', metrics=['mape'])
history = model.fit(x, y, epochs=100)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.