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 给定一棵二叉树的先序遍历 ...
随机推荐
- 真正的Maven经常使用命令
长期用Eclipse的Maven插件的小伙伴可能接触Maven的经常使用命令比較少.每次用每次翻文档. 假设让你脱离Eclipse怎么办,面试的时候考到了怎么办-- 假设你不想尴尬,请小朋友花点时间运 ...
- P2689 东南西北
题目描述 给出起点和终点的坐标及接下来T个时刻的风向(东南西北),每次可以选择顺风偏移1个单位或者停在原地.求到达终点的最少时间. 如果无法偏移至终点,输出“-1”. 输入输出格式 输入格式: 第一行 ...
- ③---Java项目管理工具MAVEN安装与配置
Java项目管理工具MAVEN安装配置以下将为大家介绍Java项目管理工具MAVEN安装及其配置. 一.下载MAVEN安装文件 maven下载地址:https://maven.apache.org/d ...
- Linux之RTOS学习
Linux之RTOS学习 RTOS: Real time operating system 系统选型 可选方案 RTLinux - FSMLabs, WindRiver Systems - http: ...
- (二 -5) 天猫精灵接入Home Assistant-自动发现Mqtt设备--电风扇
官网:https://www.home-assistant.io/components/fan.mqtt/ 1 添加配置文件 要在安装中启用MQTT风扇,请将以下内容添加到您的configuratio ...
- linux上安装完torch后仍报错:ImportError: No module named torch
linux上安装完torch后仍报错: Traceback (most recent call last): File , in <module> import torch ImportE ...
- 从高德采集最新的省市区三级坐标和行政区域边界,用js在浏览器中运行
本文描述的是对国家统计局于2019-01-31发布的<2018年统计用区划代码和城乡划分代码(截止2018年10月31日)>中省市区三级的坐标和行政区域边界的采集. 本文更新(移步查阅): ...
- iOS开发简记(8):数据持久化
数据持久化,也就是把数据保存到磁盘,以后可以再读取出来使用(也可以再次更改或删除).很多场景需要数据持久化,比如为了减轻服务器的访问与存储压力,客户端需要在本地做一些数据持久化的工作. iOS的数据持 ...
- 抓包工具Charles的使用心得
简介 Charles其实是一款代理服务器,通过成为电脑或者浏览器的代理,然后截取请求和请求结果达到分析抓包的目的.该软件是用Java写的,能够在Windows,Mac,Linux上使用.开发iOS都在 ...
- python中Metaclass的理解
今天在学习<python3爬虫开发实战>中看到这样一段代码3 class ProxyMetaclass(type): def __new__(cls, name, bases, attrs ...