• 大小: 17.45MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-25
  • 语言: 其他
  • 标签: 入侵检测  kdd99  

资源简介

基于Tensorflow用CNN(卷积神经网络)处理kdd99数据集,代码包括预处理代码和分类代码,准确率99.6%以上,并且快速收敛至最优值。 (Based on Tensorflow (convolutional neural network) processing KDD99 data set based on CNN, the code includes preprocessing code and classification code, the accuracy rate is more than 99.6%, and quickly converge to the optimal value.)

资源截图

代码片段和文件信息

#/usr/bin/python2.7
#coding:utf-8

from __future__ import print_function
import tensorflow as tf
import randomcsv


def next_batch(feature_listlabel_listsize):
    feature_batch_temp=[]
    label_batch_temp=[]
    f_list = random.sample(range(len(feature_list)) size)
    for i in f_list:
        feature_batch_temp.append(feature_list[i])
    for i in f_list:
        label_batch_temp.append(label_list[i])
    return feature_batch_templabel_batch_temp

def weight_variable(shapelayer_name):
    #定义一个shape形状的weights张量
    with tf.name_scope(layer_name + ‘_Weights‘):
        Weights = tf.Variable(tf.truncated_normal(shape stddev=0.1)name=‘W‘)
    tf.histogram_summary(layer_name + ‘_Weights‘ Weights)
    return Weights

def bias_variable(shapelayer_name):
    #定义一个shape形状的bias张量
    with tf.name_scope(layer_name + ‘_biases‘):
        biases = tf.Variable(tf.constant(0.1 shape=shape)name=‘b‘)
    tf.histogram_summary(layer_name + ‘_biases‘ biases)
    return biases

def conv2d(x Wlayer_name):
    #卷积计算函数
    # stride [1 x步长 y步长 1]
    # padding:SAME/FULL/VALID(边距处理方式)
    with tf.name_scope(layer_name + ‘_h_conv2d‘):
        h_conv2d = tf.nn.conv2d(x W strides=[1 1 1 1] padding=‘SAME‘)
    return h_conv2d

def max_pool_2x2(xlayer_name):
    # max池化函数
    # ksize [1 x边长 y边长1] 池化窗口大小
    # stride [1 x步长 y步长 1]
    # padding:SAME/FULL/VALID(边距处理方式)
    with tf.name_scope(layer_name + ‘_h_pool‘):
        h_pool = tf.nn.max_pool(x ksize=[1221] strides=[1221] padding=‘SAME‘)
    return h_pool
def load_data():
    global feature
    global label
    global feature_full
    global label_full
    feature=[]
    label=[]
    feature_full=[]
    label_full=[]
    file_path =‘/home/peter/Desktop/pycharm/ids-kdd99/kddcup.data_10_percent_corrected_handled2.cvs‘
    with (open(file_path‘r‘)) as data_from:
        csv_reader=csv.reader(data_from)
        for i in csv_reader:
            # print i
            label_list=[0]*23
            feature.append(i[:36])
            label_list[int(i[41])]=1
            label.append(label_list)
            # print label
            # print feature
    file_path_full =‘/home/peter/Desktop/pycharm/ids-kdd99/kddcup.data.corrected_handled2.cvs‘
    with (open(file_path_full‘r‘)) as data_from_full:
        csv_reader_full=csv.reader(data_from_full)
        for j in csv_reader_full:
            # print i
            label_list_full=[0]*23
            feature_full.append(j[:36])
            label_list_full[int(j[41])]=1
            label_full.append(label_list_full)
if __name__  == ‘__main__‘:
    global feature
    global label
    global feature_full
    global label_full
    # load数据
    load_data()
    feature_test = feature
    feature_train =feature_full
    label_test = label
    label_test_full = label_full
    # 定义用以输入的palceholder
    with tf.name_scope(‘inputs‘):
        xs = tf.placeholder(tf.float32 [None 36]name=‘pic_data‘) # 6x6
        ys = tf.placeholder(tf.float32 [None 23]

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-06-08 20:49  ids-kdd99\
     目录           0  2017-06-08 20:49  ids-kdd99\.idea\
     文件         398  2016-12-27 15:54  ids-kdd99\.idea\ids-kdd99.iml
     文件         682  2016-12-27 15:53  ids-kdd99\.idea\misc.xml
     文件         270  2016-12-27 15:53  ids-kdd99\.idea\modules.xml
     文件       42708  2016-12-29 10:01  ids-kdd99\.idea\workspace.xml
     文件        6944  2016-12-29 16:58  ids-kdd99\cnn_main.py
     文件        2977  2016-12-29 16:55  ids-kdd99\handle2.py
     文件    18115902  2016-12-29 09:58  ids-kdd99\kddcup.data.gz
     文件     2144903  2016-12-28 16:45  ids-kdd99\kddcup.data_10_percent.gz
     文件        4659  2016-12-29 17:00  ids-kdd99\main.py
     文件        6944  2017-02-27 15:12  ids-kdd99\mian_cnn.py
     目录           0  2017-06-08 20:49  ids-kdd99\multi_logs\
     文件       53246  2016-12-29 11:38  ids-kdd99\multi_logs\events.out.tfevents.1482980284.zjx-24000635
     目录           0  2017-06-08 20:49  ids-kdd99\multi_logs\test\
     文件      155823  2016-12-29 11:38  ids-kdd99\multi_logs\test\events.out.tfevents.1482980284.zjx-24000635
     目录           0  2017-06-08 20:49  ids-kdd99\multi_logs\train\
     文件      155823  2016-12-29 11:38  ids-kdd99\multi_logs\train\events.out.tfevents.1482980284.zjx-24000635
     文件         328  2016-12-29 17:11  ids-kdd99\readMe.txt.txt

评论

共有 条评论