I'm currently learning about forecasting time series using a very simple dataset with 8 columns (All numbers) with a total of 795 samples for training and 89 for testing (No NaN values)
The data has been normalized using:
scaler = MinMaxScaler(feature_range=(0,1))
scaled_data = scaler.fit_transform(dataset_to_train)
Later, after separating the target from the features, I used Keras to create a LSTM (x_train is scaled_data without the target column):
lstm_net = Sequential()
lstm_net.add(LSTM(20, input_shape=(x_train.shape[1],1), return_sequences=True))
lstm_net.add(LSTM(10,return_sequences=False))
lstm_net.add(Dense(5))
lstm_net.add(Dense(1))
And for the compiling (Have tried other compilers like adam or rmsprop with no change at all):
lstm_net.compile(optimizer = 'sgd', loss = 'mean_squared_error', metrics=['accuracy'])
And for the fitting:
lstm_net.fit(x_train,y_train, epochs=50 , batch_size=1)
It shows this:
Epoch 30/50
795/795 [==============================] - 2s 2ms/step - loss: nan - accuracy: 0.0474
Which has very low accuracy and nan loss all the time.
To get the final predictions:
predictions = lstm_net.predict(x_test)
print(predictions)
And it prints a whole array of [nan]
Any advice on how can I try to solve this? Have tried everything I have found on other posts or forums and most people specify it might be due to a gradient problem, and even tried different scalers with no results so I'm lost.