Appscanner实验还原code3
# Author: Baozi
#-*- codeing:utf-8 -*-
import _pickle as pickle
from sklearn import ensemble
import random
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, classification_report, \
confusion_matrix
import numpy as np ##########
########## # TRAINING_PICKLE = 'motog-old-65-withnoise-statistical.p' # 1a
TRAINING_PICKLE = 'trunc-dataset1a-noisefree-statistical.p' # 1a
# TESTING_PICKLE = 'motog-new-65-withnoise-statistical.p' # 2
TESTING_PICKLE = 'trunc-dataset2-noisefree-statistical.p' # print('Loading pickles...')
trainingflowlist = pickle.load(open(TRAINING_PICKLE, 'rb'), encoding='iso-8859-1')
testingflowlist = pickle.load(open(TESTING_PICKLE, 'rb'), encoding='iso-8859-1')
print('Done...')
print('') print('Training with ' + TRAINING_PICKLE + ': ' + str(len(trainingflowlist)))
print('Testing with ' + TESTING_PICKLE + ': ' + str(len(testingflowlist)))
print('') for THR in range(10): p = []
r = []
f = []
a = []
c = [] for i in range(5):
print(i)
########## PREPARE STUFF
trainingexamples = []
classifier = ensemble.RandomForestClassifier()
classifier2 = ensemble.RandomForestClassifier() ########## GET FLOWS
for package, time, flow in trainingflowlist:
trainingexamples.append((flow, package))
# print('') ########## SHUFFLE DATA to ensure classes are "evenly" distributed
random.shuffle(trainingexamples) ########## TRAINING PART 1
X1_train = []
y1_train = []
#####################################################
for flow, package in trainingexamples[:int(float(len(trainingexamples)) / 2)]:
X1_train.append(flow)
y1_train.append(package) # print('Fitting classifier...')
classifier.fit(X1_train, y1_train)
# print('Classifier fitted!')
# print('' ########## TRAINING PART 2 (REINFORCEMENT)
X2_train = []
y2_train = []
tmpx_train = []
tmpy_train = [] count = 0
count1 = 0
count2 = 0 ###############################################
for flow, package in trainingexamples[int(float(len(trainingexamples)) / 2):]:
# flow = np.array(flow).reshape(1,-1)
# tmp.append(flow)
tmpx_train.append(flow)
tmpy_train.append(package) predictions = classifier.predict(tmpx_train)
#print(type(predictions))#<class 'numpy.ndarray'>
#print(predictions[0])#com.myfitnesspal.android-auto.csv
for flow, package in trainingexamples[int(float(len(trainingexamples)) / 2):]:
X2_train.append(flow)
prediction = predictions[count] if (prediction == package):
y2_train.append(package)
count1 += 1
else:
y2_train.append('ambiguous')
count2 += 1
count += 1
print("Step Finished!!!!!!!!!!!")
# print(count1)
# print(count2) # print('Fitting 2nd classifier...')
classifier2.fit(X2_train, y2_train)
# print('2nd classifier fitted!'
# print('' ########## TESTING threshold = float(THR) / 10 X_test = []
y_test = []
tmpx_test = []
tmpy_test = []
count = 0
totalflows = 0
consideredflows = 0 for package, time, flow in testingflowlist:
tmpx_test.append(flow)
tmpy_test.append(package) predictionss = classifier2.predict(tmpx_test)#此时的分类器可以预测带有ambiguous标签的样本
prediction_proba = classifier2.predict_proba(tmpx_test)#此时的分类器可以预测带有ambiguous标签的样本
#print(type(prediction_proba))#<class 'numpy.ndarray'>
print(prediction_proba[0]) for package, time, flow in testingflowlist:
prediction = predictionss[count]
if (prediction != 'ambiguous'):
prediction_probability = max(prediction_proba[0])
totalflows += 1 if (prediction_probability >= threshold):
consideredflows += 1 X_test.append(flow)
y_test.append(package)
count += 1 y_pred = classifier2.predict(X_test) p.append(precision_score(y_test, y_pred, average="macro") * 100)
r.append(recall_score(y_test, y_pred, average="macro") * 100)
f.append(f1_score(y_test, y_pred, average="macro") * 100)
a.append(accuracy_score(y_test, y_pred) * 100)
c.append(float(consideredflows) * 100 / totalflows) print('Threshold: ' + str(threshold))
print(np.mean(p))
print(np.mean(r))
print(np.mean(f))
print(np.mean(a))
print(np.mean(c))
print('')
Appscanner实验还原code3的更多相关文章
- Appscanner实验还原code2
import _pickle as pickle from sklearn import svm, ensemble import random from sklearn.metrics import ...
- Appscanner实验还原code1
import _pickle as pickle from sklearn import svm, ensemble import random from sklearn.metrics import ...
- 11.2.0.4rac service_name参数修改
环境介绍 )客户环境11. 两节点 rac,集群重启后,集群资源一切正常,应用cs架构,连接数据库报错,提示连接对象不存在 )分析报错原因,连接数据库方式:ip:Port/service_name方式 ...
- RAC环境修改参数生效测试
本篇文档--目的:实验测试在RAC环境下,修改数据库参数与单实例相比,需要注意的地方 --举例说明,在实际生产环境下,以下参数很可能会需要修改 --在安装数据库完成后,很可能没有标准化,初始化文档,没 ...
- vsftp -samba-autofs
摘要: 1.FTP文件传输协议,PAM可插拔认证模块,TFTP简单文件传输协议. 注意:iptables防火墙管理工具默认禁止了FTP传输协议的端口号 2.vsftpd服务程序三种认证模式?三种认证模 ...
- 【故障处理】ORA-12162 错误的处理
[故障处理]ORA-12162: TNS:net service name is incorrectly specified 一.1 场景 今天拿到一个新的环境,可是执行sqlplus / as s ...
- SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树
数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...
- SDUT 3343 数据结构实验之二叉树四:还原二叉树
数据结构实验之二叉树四:还原二叉树 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 给定一棵 ...
- SDUT-3343_数据结构实验之二叉树四:(先序中序)还原二叉树
数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定一棵二叉树的先序遍历 ...
随机推荐
- ElasticSearch(四):使用Java连接ElasticSearch集群
public class ESIndexMapping { private static String host="192.168.56.3"; // 服务器地址 private ...
- centos7下安装docker(15.8docker跨主机容器通信总结)
性能:underlay网络的性能优于overlay.Overlay网络利用隧道技术,将数据包封装到UDP中进行传输,由于涉及数据包的封装和解封,存在额外的CPU和网络的开销,虽然几乎所有overlay ...
- [JXOI2018]守卫
嘟嘟嘟 正如某题解所说,这题很有误导性:我就一直在想凸包. 随便一个数据,就能把凸包hack掉: 这样我们的点G就gg了. 所以正解是什么呢?dp. 题解看这位老哥的吧,我感觉挺好懂的:题解 P456 ...
- [HEOI2015]小Z的房间 && [CQOI2018]社交网络
今天看了一下矩阵树定理,然后学了一下\(O(n ^ 3)\)的方法求行列式. 哦对了,所有的证明我都没看-- 这位大佬讲的好呀: [学习笔记]高斯消元.行列式.Matrix-Tree 矩阵树定理 关于 ...
- P2678 跳石头(二分+模拟)
思路: 我觉得我现在有一个非常不好的习惯,那就是不爱画图.当我把这个题的检验函数用图来表示出来.感觉就非常好理解了. 直接说检验函数吧.就是非常简单的模拟,我现在换成角度来说:假设你最小能跳x(不能跳 ...
- 【angularJS】过滤器
1.分类: <1>内置过滤器(见4) <2>自定义过滤器 2.作用:接收一个输入,通过某个规则进行处理,然后返回处理后的结果 3.应用: <1>在模板中使用 用法 ...
- classmethod 和 staticmethod
我一般很少用到. Talk is cheap, show you the code. #!/usr/bin/env python # -*- coding: utf-8 -*- ########### ...
- npm run dev 在Linux上持久运行
关于node.js应用程序如何持久运行,我在node.js服务端程序在Linux上持久运行用过. 这次主要是针对是一个vue.js应用程序. vue.js应用程序通常运行命令是npm run dev. ...
- 【转】Java日志框架:logback详解
为什么使用logback 记得前几年工作的时候,公司使用的日志框架还是log4j,大约从16年中到现在,不管是我参与的别人已经搭建好的项目还是我自己主导的项目,日志框架基本都换成了logback,总结 ...
- kafka原理和实践(三)spring-kafka生产者源码
系列目录 kafka原理和实践(一)原理:10分钟入门 kafka原理和实践(二)spring-kafka简单实践 kafka原理和实践(三)spring-kafka生产者源码 kafka原理和实践( ...