1

I've to predict the time dependence of soil wet from the rainfall and some several time series. For all of them I've forecasts and the only to do is prediction of soil wet.

According to guide I build a CNN model, cause Arima's can't take into account outer stohastic influence.

The model work's, but not as it should. If You have a look on this picture enter image description here, You'll find that the forecasted series(yellow smsfu_sum) doesn't depend on rain (aprec series) as in training set. I want a sharp peak in forecast, but changing the sizes of kernel and pooling don't help.

So I tried to train CNN-LSTM model based on this guide

Here's code of architecture of model :

def build_model(train, n_input):
# prepare data
train_x, train_y = to_supervised(train, n_input)
# define parameters
verbose, epochs, batch_size = 1, 20, 32
n_timesteps, n_features, n_outputs = train_x.shape[1], train_x.shape[2], train_y.shape[1]
# reshape output into [samples, timesteps, features]
train_y = train_y.reshape((train_y.shape[0], train_y.shape[1], 1))
# define model
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='softmax', input_shape=(n_timesteps,n_features)))
model.add(Conv1D(filters=64, kernel_size=3, activation='softmax'))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(RepeatVector(n_outputs))
model.add(LSTM(200, activation='relu', return_sequences=True))
model.add(TimeDistributed(Dense(100, activation='softmax')))
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mse', optimizer='adam')
# fit network
model.fit(train_x, train_y, epochs=epochs, batch_size=batch_size, verbose=verbose)
return model

I used batch size = 32, and split data with function:

def to_supervised(train, n_input, n_out=300):
# flatten data
data = train.reshape((train.shape[0]*train.shape[1], train.shape[2]))
X, y = list(), list()
in_start = 0
# step over the entire history one time step at a time
for _ in range(len(data)):
    # define the end of the input sequence
    in_end = in_start + n_input
    out_end = in_end + n_out
    # ensure we have enough data for this instance
    if out_end <= len(data):
        X.append(data[in_start:in_end, :])
        y.append(data[in_end:out_end, 2])
    # move along one time step
    in_start += 1
return array(X), array(y)

Using n_input = 1000 and n_output = 480 (I've to predict for this time) So the first iteration on this Network tends the loss function to Nan.

How should I fix it? There no missing values in my data, I droped every NaNs.

  • Most probably you are facing exploding gradient issue. Try increasing the hidden layer size, see if it solves your problem. – Ahmet Jul 11 '20 at 03:18
  • @Roman Rudamenko- You can follow this SO question https://stackoverflow.com/questions/40050397/ for probable reasons of NaN loss. –  Oct 16 '20 at 16:46

0 Answers0