# Why is predicted rainfall by LSTM coming negative for some data points?

I have used supervised learning with LSTM network using tanh activation function and 0.1 dropout for time series prediction.my loss='mean_squared_error', optimizer='adam'. The predicted time series is shown below where x axis shows future months and y axis shows rainfall in mm.Orange line is predicted and blue line is actual. Some points are being predicted below 0 (negative) even though training dataset has all points having values >=0. My training dataset is of 64 years (all positive data) and I am predicting for 12 years (144 data points shown)

Model code using ReLU activation:

model = Sequential()
# LSTM model
model.add(LSTM(128, batch_input_shape=(batch_size, look_back, 1),activation='relu', stateful=True, return_sequences=False))

• Because your model is not aware of the non-negative constraint. You could try using a non-negative transformation like $\exp$ or $\max(x,0)$. Welcome to the site. – Emre Aug 13 '18 at 19:57
• Emre, that is an answer not a comment. – kbrose Aug 13 '18 at 22:50
• So if I use relu activation function, will this problem get solved? – Roy Aug 14 '18 at 7:11