I am trying to make regression tasks for time series, my data is like the below, i make window size of 10, and input feature as below, and target is the 5th column. as you see it has data of {70, 110, -100, 540,-130, 50}

My model as below:

model = Sequential((
    Conv1D(filters=filters, kernel_size=kernel_size, activation='relu',
    input_shape=(window_size, nb_series)),
    Conv1D(filters=filters, kernel_size=kernel_size, activation='relu'),
    Dense(nb_outputs, activation='linear'),
model.compile(loss='mse', optimizer='adam', metrics=['mae'])

My Input features as below:


I get the below loss and no matter how many epochs, switching between activation functions, optimizer. I understand that this is because of the mean of the output over my dataset is between 122-124 this is why i always get this value.

297055/297071 [============================>.] - ETA: 0s - loss: 22789.0087 - mean_absolute_error: 123.0670
297071/297071 [==============================] - 144s 486us/step - loss: 22788.9740 - mean_absolute_error: 123.0673 - val_loss: 10519.1722 - val_mean_absolute_error: 79.3461

And by testing the prediction using the below code:

pred = model.predict(X_test)
print('\n\nactual', 'predicted', sep='\t')
for actual, predicted in zip(y_test, pred.squeeze()):
    print(actual.squeeze(), predicted, sep='\t')

I get the below output:
for linear activation at the output layer

20.0    -0.059563223
-22.0   -0.059563223
-55.0   -0.059563223

for relu activation at the output layer:

235.0 0.0
-170.0 0.0
154.0 0.0

And Sigmoid:

-54.0   1.4216835e-36
-39.0   0.0
66.0    2.0888916e-37

Is there a way to predict continuous integers like above ?

Is it the activation function ?

Is it an issue of feature selection ?

Is it an architectural issue, maybe LSTM is better ?

Also any recommendation regarding the kernel size, filters, loss, activation and optimizer is so much appreciate.

Update: I have tried to use LSTM using the below model:

# design network
model = Sequential()
model.add(LSTM(50, input_shape=(X.shape[1], X.shape[2])))
model.compile(loss='mae', optimizer='adam', metrics=['mae'])
# fit network
model.fit(X_train, y_train, epochs=2, batch_size=10, 
validation_data=(X_test, y_test), shuffle=False)

And i got the below Loss:

297071/297071 [==============================] - 196s 661us/step - loss: 122.8202 - mean_absolute_error: 122.8202 - val_loss: 78.2440 - val_mean_absolute_error: 78.2440
Epoch 2/2
297071/297071 [==============================] - 196s 661us/step - loss: 122.3811 - mean_absolute_error: 122.3811 - val_loss: 78.4328 - val_mean_absolute_error: 78.4328

And the below predicted values:

-55.0   -45.222805
-105.0  -21.363165
29.0    -18.858946
-125.0  -34.27912
-134.0  20.847342
-108.0  30.286516
113.0   31.09069
-63.0   8.848535

Is it the architecture or the data ?

Update 2: After using MinMaxScaler and testing the predicted versus actual i got the below values, basically normalized or not i get very bad output

Expected=-51.0, Predicted=1.0 Expected=76.0, Predicted=10.4 Expected=101.0, Predicted=-19.6 Expected=-49.0, Predicted=-33.1 Expected=-56.0, Predicted=-14.4 Expected=-58.0, Predicted=-5.0 Expected=52.0, Predicted=6.1 Expected=66.0, Predicted=-15.6 Expected=-58.0, Predicted=-29.0 Expected=43.0, Predicted=-9.8


1 Answer 1


From what you have described and posted I see a few things that you could improve. Please see them below.

Are you normalizing your input/output variable? From what you posted it doesn't look like you are, correct me if I am wrong. If you are not, you definitely need to. DNN have issues when dealing with non-normalized data because of variable weights. Say you have two input features, one 100 the other 10. Apply similar weights and the feature with the larger nominal value will end up having a larger weight in the model. You can try [0,1] or [-1,1] range normalization. Although you can always Z-Score normalize too. I prefer the range normalization because they have similar max / min values. Find the calculations for range normalization below.

$\ [0,1]\ Norm = \frac{x - min(x)}{max(x)-min(x)} $

$\ [-1,1]\ Norm = 2*\frac{x - min(x)}{max(x)-min(x)}-1 $

Futhermore, try adding a dropout layer or a batch normalization layer. These reduce overfitting of the network and are generally a good idea to include in any network.

I noticed you are only using 2 epochs to train the model. This is a really low number. You aren't giving the model enough tries at refining the problem. Try a higher amount of epochs too. Adding more epochs is also useful for identify if the model is underfitting or overfitting as you can plot the loss metric over the epochs.

This is a very surface level analysis. If you need more detail let me know.


I had the very same questions you had. As a background, most of my predictive experience is in finance/trading where direction and magnitude is important. For most of my models I use [-1,1]. If find it works the best, purely my experience. To solve the direction/magnitude issue, you must consider the loss function you are using. If model predicts 1 and true data is -2, error will be 3 for that point based off a simple residual. Based off this, you should be able to convince yourself that direction is but magnitude. So using [0,1] norm shouldn't matter because the magnitude from 1 to -2 will remain the same when normalized, given the units will change.

For normalization, you just apply the inverse of the function to "de-normalize" the data. In theory, yes you could have an issue if you are predicting beyond the bounds of max(x) and min(x), but if the value predicted is within that range there will be no problem. You could just normalize the input vectors and leave the output vector untouched. The value normalization adds to the model is worth this risk. The important feature of normalizing, as said before, is all the input vectors become equivalent in units. The fact that some of your input vectors are normalized is good, but they all need to have the same normalization for you to gain the benefits.

Update 2

I'm not to familiar with CNNs, more RNNs (GRU / LSTM). So I'm not sure if there is an error in your architecture. From my research and experience, I have found RNNs very useful when it comes to time-series forecasting because of the recurrent aspects of them. The ability for them to handle temporal data is a huge benefit in my book. CNNs, from what I know, do not have this feature. Here is a link chatting about them both:


As far as a loss function, test both. Check performance. Here are a few links that compares and contrasts the loss functions available:




One last thing. Not all problems are solvable by machine learning, especially in time-series. The data could just be too noisy for the model to work. Try forecasting the SPY time-series, you will most likey come up with a subpar model. It is just too noisy. So when in doubt, start with a simple model and when it is shown not to be overfitting increase the complexity.

  • $\begingroup$ Hi, Thank you so much for your reply. I definitely need more details but let me give you more details about what i am doing. First i have always been worried about normalization, shouldn't this affect the model when it predict the real data ? or am i supposed to apply the same normalization function and values in prediction phase ? like i would use the same min(x) and max(x) ?. Second, some feature are kinda normalized. cause some of them are ratio between two features. Third, my target feature is magnitude and direction. and i need to predict both. $\endgroup$
    – Ramzy
    Nov 13, 2018 at 15:19
  • $\begingroup$ Submitted an update. Let me know if that clarifies things. $\endgroup$
    – PlantFox
    Nov 13, 2018 at 16:05
  • $\begingroup$ Really helpful, i am not sure about how to choose a loss function. $\endgroup$
    – Ramzy
    Nov 13, 2018 at 16:27
  • $\begingroup$ Regarding the LSTM vs CNN, both almost have the same loss, but LSTM got nearer values than CNN. is that issue in the model ? $\endgroup$
    – Ramzy
    Nov 13, 2018 at 16:29
  • $\begingroup$ Also i am unable to decrease the window size in CNN. $\endgroup$
    – Ramzy
    Nov 13, 2018 at 16:29

Your Answer

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

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