【问题标题】:Why Epoch showing the same accuracy?为什么 Epoch 显示相同的准确性?
【发布时间】:2021-10-26 12:29:25
【问题描述】:

我正在尝试构建 IDS 入侵检测系统并尝试预测标签是良性还是 DDos。但我在各个时期都得到了相同的准确度。

代码:

        from tensorflow import keras
    import numpy as np
    import datetime
    import time
    from tensorflow.keras.optimizers import Adam
    from keras.models import Sequential
    from keras.layers import Dense, Dropout
    from keras import callbacks
    x=pd.DataFrame(X)
    x = x.values
    sample = x.shape[0]
    features = x.shape[1]
    #Train: convert 2D to 3D for input RNN
    x_train = np.reshape(x,(sample,features,1)) #shape  = (125973, 18, 1)
    #Test: convert 2D to 3D for input RNN
    x_test=pd.DataFrame(X_test)
    x_test = x_test.values
    x_test = np.reshape(x_test,(x_test.shape[0],x_test.shape[1],1))
Model = keras.Sequential([

        keras.layers.LSTM(80,input_shape=(features,x_train.shape[2]),
                          activation='sigmoid',recurrent_activation='hard_sigmoid'),
        keras.layers.Dense(1,activation="softmax")
    ])

Model.compile(optimizer='rmsprop',loss='mse', metrics=['accuracy'])

#Training the model

Model.fit(x_train, y, epochs=10, batch_size= 32) 
Model.summary()

# Final evaluation of the model
scores = Model.evaluate(x_test, y_test, verbose=0)
print('/n')
print("Accuracy: %.2f%%" % (scores[1]*100))



Epoch 1/10
1074/1074 [==============================] - 92s 83ms/step - loss: 0.4180 - accuracy: 0.5820
Epoch 2/10
1074/1074 [==============================] - 79s 74ms/step - loss: 0.4180 - accuracy: 0.5820
Epoch 3/10
1074/1074 [==============================] - 81s 76ms/step - loss: 0.4180 - accuracy: 0.5820

解决办法是什么?

【问题讨论】:

  • 您在 tf.keras 和 keras 之间混合导入,这不是一个好主意
  • 所以我只用一个吗?

标签: machine-learning keras deep-learning lstm recurrent-neural-network


【解决方案1】:

因为"softmax"激活有1个神经元总是输出1。你的神经元不能调整它的输出来减少损失;它在数学上只能返回 1。

【讨论】:

  • 推荐的调整是什么?
  • 您应该查看任务的损失函数、指标和激活函数。似乎这是一个 2 类问题,所以"sigmoid" 激活会起作用,"binary_crossentropy" 是损失
猜你喜欢
  • 2021-02-01
  • 2019-08-29
  • 1970-01-01
  • 2022-01-04
  • 2020-11-02
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 2016-12-13
相关资源
最近更新 更多