我的数据集是卫星观测,其中包括很多零,使高度影响我的最终模拟结果。
我有两组输入数据,动态数据(X_dynamic_LSTM.shape(95931,1,5))随时间序列变化,静态数据(X_static_MLP.shape(95931,10))不变。对于动态数据,我使用LSTM;对于静态数据,我使用MLP。我将这两组数据连接起来,并通过另一个MLP获得最终结果。
你能建议我如何在我的预测 Dataframe 中忽略这些零变量吗??我知道掩码和嵌入,但不知道如何在我的代码中添加它们!
from tensorflow.keras.layers import Input, LSTM, Dense, Concatenate
from tensorflow.keras.models import Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Masking
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Embedding
lstm_input = Input(shape=(X_dynamic_LSTM.shape[1], X_dynamic_LSTM.shape[2]))
x = Masking(mask_value=0.)(lstm_input)
x = LSTM(70, activation='tanh', return_sequences=True)(x)
x = Dropout(0.3)(x)
x = LSTM(35)(x)
x = Dropout(0.3)(x)
x = Dense(1, activation='tanh')(x)
#mlp input with additonal 3 variables at t=t
mlp_input=Input(shape=(X_static_MLP.shape[1]))
mlp = Dense(30, activation='relu')(mlp_input)
mlp = Dense(20, activation='relu')(mlp)
merge = Concatenate()([x, mlp])
hidden1 = Dense(5, activation='relu')(merge)
mlp_out = Dense(1, activation='relu')(hidden1)
model = Model(inputs=[lstm_input, mlp_input],outputs=mlp_out)
#compile the model
model.compile(loss='mae', optimizer='adam')
#fit the model
model.fit([X_dynamic_LSTM, X_static_MLP], y_train, batch_size=40,
epochs=10, validation_split=0.2)
1条答案
按热度按时间lrpiutwd1#
使用嵌入层在你的第一层
你可以使用这个link