0

I have an LSTM code but when I increase the window size, it is not working anymore. is there someone who knows how to fix this? I think it is because of [i+i+window_size], but I do not know how I can change this.

    def df_to_X_y(df, window_size=168):
  df_as_np = df.to_numpy()
  X = []
  y = []
  for i in range(len(df_as_np)-window_size):
    row = [r for r in df_as_np[i:i+window_size]]
    X.append(row)
    label = df_as_np[i+window_size][0]
    y.append(label)
  return np.array(X), np.array(y)

WINDOW_SIZE = 168
X, y = df_to_X_y(allmerged)

X_train, y_train = X[:98240], y[:98240]
X_val, y_val = X[98240:112274], y[98240:112274]
X_test, y_test = X[112274:], y[112274:]
X_train.shape, y_train.shape, X_val.shape, y_val.shape, X_test.shape, y_test.shape

def preprocess(X):
    num_vars = X.shape[2]
    mean = np.mean(X, axis=(0, 1))
    std = np.std(X, axis=(0, 1))
    for i in range(num_vars):
        X[:, :, i] = (X[:, :, i] - mean[i]) / std[i]
    return X


preprocess(X_train)
preprocess(X_val)
preprocess(X_test)

model4 = Sequential()
model4.add(InputLayer((168, 10)))
model4.add(LSTM(64))
model4.add(Dense(8, 'relu'))
model4.add(Dense(1, 'linear'))

model4.summary()
J1999
  • 3
  • 2

0 Answers0