友:你要不要一起參加鐵人賽?
我:好啊!
(幾天後)
我:乾我不小心忘了報名......
--------------------------------------> 2021.09.17
今天會使用的的模型是常見的LSTM及GRU。一樣的是,網路上有許多優質的解說文章,大家可以先去做點功課。
train_data # (2984, 7, 4)
train_label # (2984, )
lstm_model = K.Sequential()
lstm_model.add(K.layers.LSTM(units=256, return_sequences=True, input_shape=(7, 4)))
lstm_model.add(K.layers.Dropout(0.3214))
lstm_model.add(K.layers.LSTM(units=64))
lstm_model.add(K.layers.Dropout(0.1432))
lstm_model.add(K.layers.Dense(units=1, activation='sigmoid'))
lstm_model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
gru_model = K.Sequential()
gru_model.add(K.layers.GRU(units=256, return_sequences=True, input_shape=(7, 4)))
gru_model.add(K.layers.Dropout(0.3214))
gru_model.add(K.layers.GRU(units=64))
gru_model.add(K.layers.Dropout(0.1432))
gru_model.add(K.layers.Dense(units=1, activation='sigmoid'))
gru_model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
train_data = np.array(train_data)
train_label = np.array(train_label)
split_num = int(len(train_data)*0.8)
train_data, test_data = train_data[:split_num], train_data[split_num:]
train_label, test_label = train_label[:split_num], train_label[split_num:]
lstm_model.fit(train_data, train_label, validation_split=0.14, epochs=50, batch_size=64, verbose=0)
gru_model.fit(train_data, train_label, validation_split=0.14, epochs=50, batch_size=64, verbose=0)
lstm_pred = lstm_model.evaluate(test_data, test_label)
gru_pred = gru_model.evaluate(test_data, test_label)