1

我使用一个循环网络(在特殊的 GRU 中)来预测一个长度为 90 次的时间序列。数据的类型是多变量的,下面这个例子。

多变量时间序列

选项1:

我使用 keras 开发 rnn

n_train_quarter = int(len(serie) * 0.75)
train = values[:n_train_quarter, :]
test = values[n_train_quarter:, :]
X_train, y_train = train[:, :-1], train[:, - 1]
X_test, y_test = test[:, :-1], test[:, - 1]

# All parameter can be changes kernel, activation, optimizer, ...
model = Sequential()
model.add(GRU(64, input_shape=(X_train.shape[1], X_train.shape[2]),return_sequences=True))
model.add(Dropout(0.5))

# n is random
for i in range(n)
    model.add(GRU(64,kernel_initializer = 'uniform', return_sequences=True))
    model.add(Dropout(0.5))

model.add(Flatten())
model.add(Dense(1))
model.add(Activation('softmax'))

#Compile and fit
model.compile(loss='mean_squared_error', optimizer='SGD')
early_stopping = EarlyStopping(monitor='val_loss', patience=50)
checkpointer = ModelCheckpoint(filepath=Checkpoint_mode, verbose=0, save_weights_only=False, save_best_only=True)
model.fit(X_train, y_train,
          batch_size=256,
          epochs=64,
          validation_split=0.25,
          callbacks=[early_stopping, checkpointer],
          verbose=0,
          shuffle=False)

并且误差较小的结果看起来像图像(有相同结果的各种实验)

绘图选项 1

选项 2:

X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = 0.33, random_state = 42)

# All parameter can be changes kernel, activation, optimizer, ...
model = Sequential()
model.add(GRU(64, input_shape=(X_train.shape[1], X_train.shape[2]),return_sequences=True))
model.add(Dropout(0.5))

# n is random
for i in range(n)
    model.add(GRU(64,kernel_initializer = 'uniform', return_sequences=True))
    model.add(Dropout(0.5))

model.add(Flatten())
model.add(Dense(1))
model.add(Activation('softmax'))

#Compile and fit
model.compile(loss='mean_squared_error', optimizer='SGD')
early_stopping = EarlyStopping(monitor='val_loss', patience=50)
checkpointer = ModelCheckpoint(filepath=Checkpoint_mode, verbose=0, save_weights_only=False, save_best_only=True)
model.fit(X_train, y_train,
          batch_size=256,
          epochs=64,
          validation_split=0.25,
          callbacks=[early_stopping, checkpointer],
          verbose=0,
          shuffle=False)

并且错误较少的结果打印为

选项 2 结果

可以将sklearn的“train_test_split”与随机选择的数据一起使用吗?

如果 GRU 对连续数据更好,为什么连续数据的结果比随机选择数据更好?

4

0 回答 0