我想为分类问题建立一个神经网络。训练集需要394个输入(共48个维度),并具有100个验证集。代码为:
def build_model():
model = Sequential()
model.add(Dense(2, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(2, activation = "relu"))
model.add(Dropout(0.2))
model.add(Dense(2, activation = "sigmoid"))
model.add(Dropout(0.1))
model.add(Dense(2, activation = "softmax"))
model.compile(
optimizer=tf.keras.optimizers.Adam(learning_rate=0.000001),
loss=['mean_squared_error'],
metrics=['accuracy']
)
return model
model = build_model()
history = model.fit(
x_train,
y_train,
epochs=5,
batch_size=32,
validation_data=(
x_val,
y_val
),
callbacks=[ProgbarLogger(count_mode='steps',stateful_metrics=None)
]
)
但是我得到了输出奇怪的日志,例如:
训练394个样本,验证100个样本
Epoch 1/5
Epoch 1/5
13/13 [==============================] - 1s 113ms/step - loss: nan - accuracy: 0.9975 - val_loss: nan - val_accuracy: 1.0000
394/394 [==============================] - 1s 4ms/sample - loss: nan - accuracy: 0.9975 - val_loss: nan - val_accuracy: 1.0000
Epoch 2/5
Epoch 2/5
13/13 [==============================] - 0s 5ms/step - loss: nan - accuracy: 1.0000 - val_loss: nan - val_accuracy: 1.0000
394/394 [==============================] - 0s 167us/sample - loss: nan - accuracy: 1.0000 - val_loss: nan - val_accuracy: 1.0000
Epoch 3/5
Epoch 3/5
13/13 [==============================] - 0s 7ms/step - loss: nan - accuracy: 1.0000 - val_loss: nan - val_accuracy: 1.0000
394/394 [==============================] - 0s 217us/sample - loss: nan - accuracy: 1.0000 - val_loss: nan - val_accuracy: 1.0000
Epoch 4/5
Epoch 4/5
13/13 [==============================] - 0s 5ms/step - loss: nan - accuracy: 1.0000 - val_loss: nan - val_accuracy: 1.0000
394/394 [==============================] - 0s 162us/sample - loss: nan - accuracy: 1.0000 - val_loss: nan - val_accuracy: 1.0000
Epoch 5/5
Epoch 5/5
13/13 [==============================] - 0s 6ms/step - loss: nan - accuracy: 1.0000 - val_loss: nan - val_accuracy: 1.0000
394/394 [==============================] - 0s 217us/sample - loss: nan - accuracy: 1.0000 - val_loss: nan - val_accuracy: 1.0000
您能帮我了解这种行为的损失和准确性吗?不应该更低吗?