反应精度:Keras模型中为0.0000e + 00

时间:2020-05-03 05:23:30

标签: tensorflow machine-learning keras

下面是我的Keras模型,用于训练数据集,其中training_x设置为4个带浮点的输入,training_y设置为0或1。 对于第一个时期,它的精度约为3.6000e-05。 然后,它给出了精度:在整个过程的第二个纪元开始时,为0.0000e + 00。我不是如何解决它。你能给我一些建议吗?

import numpy as np
import pandas as pd

from keras.models import Sequential

model = Sequential()

from keras.layers import Dense

model.add(Dense(units=128, activation='selu', input_dim=4))

model.add(Dense(units=64, activation='selu'))

model.add(Dense(units=1, activation='softmax'))


model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

CSV_FILE = "ddos.csv"
df = pd.read_csv(CSV_FILE)
df.loc[(df.Label == "ddos"), "Label"] = 1
df.loc[(df.Label == "Benign"), "Label"] = 0

x_train = np.array(df[["Flow Pkts/s", "Flow IAT Mean", "Flow IAT Max", "Flow IAT Min"]])
y_train = np.array(df[["Label"]])


# x_train and y_train are Numpy arrays --just like in the Scikit-Learn API.
model.fit(x_train, y_train, epochs=100, batch_size=128)

这是纪元2的输出:

1991296/2000000 [============================>.] - ETA: 0s - loss: nan - accuracy: 3.6157e-05
1994368/2000000 [============================>.] - ETA: 0s - loss: nan - accuracy: 3.6102e-05
1998208/2000000 [============================>.] - ETA: 0s - loss: nan - accuracy: 3.6032e-05
2000000/2000000 [==============================] - 33s 17us/step - loss: nan - accuracy: 3.6000e-05
Epoch 2/100

    128/2000000 [..............................] - ETA: 25:27 - loss: nan - accuracy: 0.0000e+00
   3840/2000000 [..............................] - ETA: 1:17 - loss: nan - accuracy: 0.0000e+00 
   8064/2000000 [..............................] - ETA: 49s - loss: nan - accuracy: 0.0000e+00 
  11776/2000000 [..............................] - ETA: 42s - loss: nan - accuracy: 0.0000e+00
  16256/2000000 [..............................] - ETA: 36s - loss: nan - accuracy: 0.0000e+00
  20096/2000000 [..............................] - ETA: 34s - loss: nan - accuracy: 0.0000e+00

1 个答案:

答案 0 :(得分:0)

  • 您的最终激活功能似乎不正确。

    通常,对于具有1个输出神经元的二进制分类问题,我们使用sigmoid激活函数而不是softmax

  • 尝试规范化数据。删除数据框中的任何nan或缺少的值。

x_train = (x_train - np.max(x_train))/(np.max(x_train) - np.min(x_train))
y_train = np.array(y_train, dtype = 'float32')

使用xyfloat32而不是整数。

df.loc[(df.Label == "ddos"), "Label"] = 1.
df.loc[(df.Label == "Benign"), "Label"] = 0.
相关问题