我正在尝试开发一个基于深入学习的入侵检测系统。
我们模拟了一个正常的网络流量,并在CSV文件(网络数据包字段的数值数据集(IP源、端口等)中编写。但是我没有异常(恶意)数据包来训练神经网络。
我搜索了类似的问题,我发现自动编码器是一种很好的无监督学习方法,但问题是我对深入学习很陌生,我只找到了这个示例https://blog.keras.io/building-autoencoders-in-keras.html,他们在图像数据集上使用自动编码器。
我希望在数值CSV数据集中使用自动编码器(或任何在我的情况下有用的东西),以预测传入数据包是正常的还是恶意的。
有什么建议吗?
发布于 2017-05-04 05:07:35
我找到了答案:
您可以使用例如numpy加载文本将数值数据集加载到python中。然后,指定编解码网络(基本上使用Keras层模块来设计神经网络)。确保编码器的输入层接受您的数据,解码器的输出层具有相同的维度。然后,再用Keras损失指定适当的损失函数(最小二乘、交叉熵等)。最后,使用(意外!)指定优化器。Keras优化器
就这样,你完蛋了!点击“run”,并观看您的自动编码器自动编码(因为这是自动编码器的工作方式)。如果您想要一个关于如何构建这个的很好的教程。
发布于 2019-08-13 09:33:36
from keras.layers import Input,Dense
from keras.models import Model
# number of neurons in the encoding hidden layer
encoding_dim = 5
# input placeholder
input_data = Input(shape=(6,)) # 6 is the number of features/columns
# encoder is the encoded representation of the input
encoded = Dense(encoding_dim, activation ='relu')(input_data)
# decoder is the lossy reconstruction of the input
decoded = Dense(6, activation ='sigmoid')(encoded) # 6 again number of features and should match input_data
# this model maps an input to its reconstruction
autoencoder = Model(input_data, decoded)
# this model maps an input to its encoded representation
encoder = Model(input_data, encoded)
# model optimizer and loss
autoencoder = Model(input_data, decoded)
# loss function and optimizer
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
# train test split
from sklearn.model_selection import train_test_split
x_train, x_test, = train_test_split(data, test_size=0.1, random_state=42)
# train the model
autoencoder.fit(x_train,
x_train,
epochs=50,
batch_size=256,
shuffle=True)
autoencoder.summary()
# predict after training
# note that we take them from the *test* set
encoded_data = encoder.predict(x_test)
https://stackoverflow.com/questions/43739224
复制相似问题