如何解决:丢失,准确度,验证丢失和验证准确度在几个时期后不会改变

时间:2019-05-31 09:42:54

标签: tensorflow machine-learning keras deep-learning jupyter-notebook

我想预测一个伪造数据集的0/1值。输入是一个长度为15的数组(所有整数),输出为0/1。我在Keras上构建了一个具有密集层的网络(仅进行实验)。仅仅经过几个时期,损失就不会改善,准确性也不会改变。我使用了二进制交叉熵,因为它是0/1的预测。我在做什么错了?

model = Sequential()

model.add(Dense(15,input_shape=(15,)))
model.add(Dense(30, activation='sigmoid'))
model.add(Dense(30, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(15,activation='sigmoid'))
model.add(Dense(1,activation='sigmoid'))
model.compile(
    optimizer=keras.optimizers.SGD(lr=0.1, momentum=0.9),
    loss='binary_crossentropy',
    metrics=['accuracy'])
Epoch 1/100
2/2 [==============================] - 1s 328ms/step - loss: 1.0643 - acc: 0.1987 - val_loss: 0.7255 - val_acc: 0.2600
Epoch 2/100
2/2 [==============================] - 0s 16ms/step - loss: 0.6485 - acc: 0.5040 - val_loss: 0.5759 - val_acc: 0.7400
Epoch 3/100
2/2 [==============================] - 0s 47ms/step - loss: 0.4991 - acc: 0.8013 - val_loss: 0.6764 - val_acc: 0.7400
Epoch 4/100
2/2 [==============================] - 0s 47ms/step - loss: 0.5626 - acc: 0.8013 - val_loss: 0.7882 - val_acc: 0.7400
Epoch 5/100
2/2 [==============================] - 0s 55ms/step - loss: 0.6252 - acc: 0.8013 - val_loss: 0.8362 - val_acc: 0.7400
Epoch 6/100
2/2 [==============================] - 0s 55ms/step - loss: 0.6406 - acc: 0.8013 - val_loss: 0.8158 - val_acc: 0.7400
Epoch 7/100
2/2 [==============================] - 0s 62ms/step - loss: 0.6090 - acc: 0.8013 - val_loss: 0.7515 - val_acc: 0.7400
Epoch 8/100
2/2 [==============================] - 0s 55ms/step - loss: 0.5592 - acc: 0.8013 - val_loss: 0.6740 - val_acc: 0.7400
Epoch 9/100
2/2 [==============================] - 0s 47ms/step - loss: 0.5125 - acc: 0.8013 - val_loss: 0.6140 - val_acc: 0.7400
Epoch 10/100
2/2 [==============================] - 0s 62ms/step - loss: 0.5076 - acc: 0.8013 - val_loss: 0.5828 - val_acc: 0.7400
Epoch 11/100
2/2 [==============================] - 0s 47ms/step - loss: 0.5090 - acc: 0.8013 - val_loss: 0.5746 - val_acc: 0.7400
Epoch 12/100
2/2 [==============================] - 0s 55ms/step - loss: 0.5247 - acc: 0.8013 - val_loss: 0.5746 - val_acc: 0.7400
Epoch 13/100
2/2 [==============================] - 0s 70ms/step - loss: 0.5270 - acc: 0.8013 - val_loss: 0.5747 - val_acc: 0.7400
Epoch 14/100
2/2 [==============================] - 0s 39ms/step - loss: 0.5192 - acc: 0.8013 - val_loss: 0.5763 - val_acc: 0.7400
Epoch 15/100
2/2 [==============================] - 0s 62ms/step - loss: 0.5058 - acc: 0.8013 - val_loss: 0.5826 - val_acc: 0.7400
Epoch 16/100
2/2 [==============================] - 0s 47ms/step - loss: 0.5000 - acc: 0.8013 - val_loss: 0.5920 - val_acc: 0.7400
Epoch 17/100
2/2 [==============================] - 0s 55ms/step - loss: 0.4987 - acc: 0.8013 - val_loss: 0.6023 - val_acc: 0.7400
Epoch 18/100
2/2 [==============================] - 0s 55ms/step - loss: 0.5013 - acc: 0.8013 - val_loss: 0.6083 - val_acc: 0.7400
Epoch 19/100
2/2 [==============================] - 0s 47ms/step - loss: 0.5050 - acc: 0.8013 - val_loss: 0.6088 - val_acc: 0.7400
Epoch 20/100
2/2 [==============================] - 0s 55ms/step - loss: 0.5041 - acc: 0.8013 - val_loss: 0.6044 - val_acc: 0.7400
Epoch 21/100
2/2 [==============================] - 0s 55ms/step - loss: 0.5058 - acc: 0.8013 - val_loss: 0.5984 - val_acc: 0.7400
Epoch 22/100
2/2 [==============================] - 0s 62ms/step - loss: 0.5020 - acc: 0.8013 - val_loss: 0.5913 - val_acc: 0.7400
Epoch 23/100
2/2 [==============================] - 0s 47ms/step - loss: 0.4992 - acc: 0.8013 - val_loss: 0.5860 - val_acc: 0.7400
Epoch 24/100
2/2 [==============================] - 0s 55ms/step - loss: 0.5001 - acc: 0.8013 - val_loss: 0.5824 - val_acc: 0.7400
Epoch 25/100
2/2 [==============================] - 0s 55ms/step - loss: 0.4990 - acc: 0.8013 - val_loss: 0.5799 - val_acc: 0.7400

哪种是处理此类数据/问题的最佳方法

1 个答案:

答案 0 :(得分:0)

我曾经遇到过类似的问题。

介于计算的概率数和您选择的激活函数之间。当您执行二进制分类时,这很棘手。如果选择了S型函数,则只需看一下函数,如果只有一个x,则该值是固定的。

解决方案: 将输出层中的节点数从1更改为2。

让我知道是否可以解决此问题。