trainData.shape =(25000,700,50),形状如下:
[[[ 0.7095 0.863 0.712 ... 0.02715 -1.305 0.5195 ]
[-0.66 1.715 -1.934 ... 0.5684 0.754 0.2593 ]
[-0.3533 2.256 -1.292 ... -0.2708 0.6714 -1.128 ]
...
[ 0. 0. 0. ... 0. 0. 0. ]
[ 0. 0. 0. ... 0. 0. 0. ]
[ 0. 0. 0. ... 0. 0. 0. ]]
...
trainLabel.shape =(25000,),,形状如下:
[1. 1. 1. ... 0. 0. 0.]
使用它们来训练MLP模型,我应该如何重塑trainData和trainLabel?详细代码如下:
def MySimpleMLP(feature=700, vec_size=50):
auc_roc = LSTM.as_keras_metric(tf.compat.v1.metrics.auc)
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=(feature * vec_size,)))
model.add(Dropout(0.2))
model.add(Dense(32, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(1, activation='softmax'))
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=[auc_roc])
return model
......
model.fit(trainData, trainLabel, validation_split=0.2, epochs=10, batch_size=64, verbose=2)
请帮助。
答案 0 :(得分:0)
尝试像这样添加Flatten
层:
def MySimpleMLP(feature=700, vec_size=50):
auc_roc = LSTM.as_keras_metric(tf.compat.v1.metrics.auc)
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=(feature * vec_size,)))
model.add(Dropout(0.2))
model.add(Dense(32, activation='relu'))
model.add(Flatten())
model.add(Dropout(0.2))
model.add(Dense(1, activation='softmax'))
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=[auc_roc])
return model
......
model.fit(trainData, trainLabel, validation_split=0.2, epochs=10, batch_size=64, verbose=2)
Flatten
将(num_of_samples,64,32,32)数组转换为(num_of_samples,64 * 32 * 32)数组,即它使数组成为2D,这正是您所需要的。>