資源簡介
親測好用 基于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.)
(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.xm
?????文件?????????270??2016-12-27?15:53??ids-kdd99\.idea\modules.xm
?????文件???????42708??2016-12-29?10:01??ids-kdd99\.idea\workspace.xm
?????文件????????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
- 上一篇:物流管理系統全套開發).rar
- 下一篇:某集團大數據平臺整體方案建議書 .docx
評論
共有 條評論