我正在努力训练一个LSTM网络,以进一步预测时间。我有一个问题清单,目前的问题是基于其中一个。
验证损失(使用mse)总是低于列车损失(mse),我知道我是在拟合,因此,概括相当糟糕。
因此,至少在某一段时间内,网络中会带来什么变化。下面是相同的代码。
learning_rate = 0.001 n_neurons = [150, 80, 60, 40, 25, 10] dropout = 0.2
def fit_lstm(train, n_lag, n_seq, n_batch, nb_epoch, n_neurons, dropout=dropout, reset_state=False): # reshape training into [samples, timesteps, features]... X, y = train[:, :n_lag], train[:, n_lag:] X = X.reshape(X.shape[0], 1, X.shape[1]) # design network.. model = Sequential() model.add(LSTM(n_neurons[5], batch_input_shape=(n_batch, X.shape[1], X.shape[2]), dropout_U=dropout, stateful=True, return_sequences=True)) model.add(LSTM(n_neurons[5], batch_input_shape=(n_batch, X.shape[1], X.shape[2]), dropout_U=dropout, stateful=True, return_sequences=True)) model.add(LSTM(n_neurons[5], batch_input_shape=(n_batch, X.shape[1], X.shape[2]), stateful=True, return_sequences=False)) model.add(Dense(y.shape[1], activation='tanh')) tic = time.time() model.compile(optimizer=adam, loss='mse') #, metrics=[mean_absolute_percentage_error] # fit network.. loss, val_loss = list(), list() for i in range(nb_epoch): print('Running Epoch ==> %s' %i)
`history = model.fit(X, y, nb_epoch=1, batch_size=n_batch, validation_split=0.1, callbacks=[early_stop,reduce_lr], verbose=2, shuffle=False) loss.append(history.history['loss']) val_loss.append(history.history['val_loss']) model.reset_states() ## clears the state... toc = time.time() print('====='*10) print('Total computation time to train the Model : %0.2f' %((toc - tic) * 100) + ' secs')` `return model, loss, val_loss` 任何帮助都是非常感谢的。
提前谢谢。
发布于 2017-09-05 10:41:50
首先重要的是检查目标是否在-1,1范围内,因为您有一个“tanh”作为输出函数。您还应该分析目标的分布(True类)。
然后,我建议的第一步之一是尝试过适合您的模型。让模型“足够复杂”,并将初始数据集的一小部分(可能是20%?)
如果您的模型不过分适合,有两种可能:
如果您的模型适合(好兆头):
https://datascience.stackexchange.com/questions/22832
复制相似问题