【发布时间】:2021-11-08 11:22:40
【问题描述】:
我有以下用于二元分类的神经网络。问题是它总是预测相同的类别(类别 1,或正类别)。我尝试对负类进行过采样,使正类的比率约为 43%,但模型仍然产生 1。基本上,它没有进行任何训练。
tf.reset_default_graph()
sess = tf.InteractiveSession()
input1 = Input(shape=(10,100)) #number of time steps and number of features
lstm1 = LSTM(units=10)(input1)
dense_1 = Dense(8, activation='relu')(lstm1)
dense_2 = Dense(4, activation='relu')(dense_1)
dense_3 = Dense(1, activation='softmax')(dense_2)
model = Model(inputs=[input1],outputs=[dense_3])
# compile the model
opt = Adam(lr=1e-06)
model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])
model.summary()
batch_size = 32
epochs = 100
callbacks = [ModelCheckpoint(filepath='best_Doc2Vec_LSTM.h5', monitor='val_loss', save_best_only=True)]
train_history = model.fit([Data_x_train],
[Data_y_train], batch_size=batch_size, epochs=epochs, validation_data=(Data_x_val, Data_y_val), callbacks = callbacks, verbose = 2)
【问题讨论】:
-
这个问题很模糊,考虑改写和添加细节。我个人认为这个问题在datascience.stackexchange.com上会更好
-
模型仍然产生 1,您正在使用带有 1 个神经元的 softmax。
-
@Luke,我想知道网络结构是否有问题。哪一部分是模糊的?我可以添加哪些信息?
-
@MRM
softmax创建一个概率之和为 1 的输出分布。因此,如果您有 1 个神经元,则它始终为 1。请尝试使用sigmoid,或最后更改使用softmax将神经元分层为 2,并更改您的损失函数。 -
@MRM 如果是这样,那么是的,尝试在隐藏层中添加更多神经元,因为 8 和 4 对于您的模型而言相对较低。
标签: keras neural-network lstm recurrent-neural-network