machine-learning - 为什么 Epoch 显示相同的准确性?
问题描述
我正在尝试构建 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
解决办法是什么?
解决方案
因为"softmax"
1 个神经元的激活总是输出 1。你的神经元无法调整其输出以减少损失;它在数学上只能返回 1。
推荐阅读
- applescript - 这个重复块中的“缺失值”来自哪里?
- javascript - 如何将使用 classList.contains() 作为条件的 if 语句转换为 switch 语句?
- pandas - 熊猫根据日期范围爆炸列
- python - Python __repr__ 方法未按预期工作
- spring - 如何以我创建的注释为条件?
- c# - 使用 C# 模式匹配避免箭头模式
- azure - 如何在 Azure AD B2C 中创建具有相同电子邮件但自定义用户属性不同的用户?
- python - 返回值和打印值 Python 之间的区别:
- cordova - Phonegap - 横幅和插页式广告都在展示
- python - 如何将 subprocess.communicate() 转换为 utf-8 字符串?