CNN处理kdd99数据集tensorflow实现.zip


亲测好用 基于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.ideaids-kdd99.iml
     文件         682  2016-12-27 15:53  ids-kdd99.ideamisc.xml
     文件         270  2016-12-27 15:53  ids-kdd99.ideamodules.xml
     文件       42708  2016-12-29 10:01  ids-kdd99.ideaworkspace.xml
     文件        6944  2016-12-29 16:58  ids-kdd99cnn_main.py
     文件        2977  2016-12-29 16:55  ids-kdd99handle2.py
     文件    18115902  2016-12-29 09:58  ids-kdd99kddcup.data.gz
     文件     2144903  2016-12-28 16:45  ids-kdd99kddcup.data_10_percent.gz
     文件        4659  2016-12-29 17:00  ids-kdd99main.py
     文件        6944  2017-02-27 15:12  ids-kdd99mian_cnn.py
     目录           0  2017-06-08 20:49  ids-kdd99multi_logs
     文件       53246  2016-12-29 11:38  ids-kdd99multi_logsevents.out.tfevents.1482980284.zjx-24000635
     目录           0  2017-06-08 20:49  ids-kdd99multi_logs est
     文件      155823  2016-12-29 11:38  ids-kdd99multi_logs estevents.out.tfevents.1482980284.zjx-24000635
     目录           0  2017-06-08 20:49  ids-kdd99multi_logs rain
     文件      155823  2016-12-29 11:38  ids-kdd99multi_logs rainevents.out.tfevents.1482980284.zjx-24000635
     文件         328  2016-12-29 17:11  ids-kdd99
eadMe.txt.txt

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)