import _pickle as pickle
from sklearn import svm, ensemble
import random
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, classification_report, confusion_matrix
import numpy as np ##########
########## TRAINTESTBOUNDARY = 0.75 #PICKLE_NAME = 'lg-new-new-65-withnoise-statistical.p'
PICKLE_NAME = 'trunc-dataset1-noisefree-statistical.p' print('Loading ' + PICKLE_NAME + '...')
flowlist = pickle.load(open(PICKLE_NAME, 'rb'),encoding='iso-8859-1')
print('Done...')
print('') print('Flows loaded: ' + str(len(flowlist))) p = []
r = []
f = []
a = [] for i in range(5):
########## PREPARE STUFF
examples = []
trainingexamples = []
testingexamples = [] #classifier = svm.SVC(gamma=0.001, C=100, probability=True)
classifier = ensemble.RandomForestClassifier() ########## GET FLOWS
for package, time, flow in flowlist:
examples.append((flow, package))
print('') ########## SHUFFLE DATA to ensure classes are "evenly" distributed
random.shuffle(examples) ########## TRAINING
trainingexamples = examples[:int(TRAINTESTBOUNDARY * len(examples))] X_train = []
y_train = [] for flow, package in trainingexamples:
X_train.append(flow)
y_train.append(package) print('Fitting classifier...')
classifier.fit(X_train, y_train)
print('Classifier fitted!')
print('') ########## TESTING
counter = 0
correct = 0 testingexamples = examples[int(TRAINTESTBOUNDARY * len(examples)):] X_test = []
y_test = []
y_pred = [] for flow, package in testingexamples:
X_test.append(flow)
y_test.append(package) ##### y_pred = classifier.predict(X_test)
print("########################")
print(precision_score(y_test, y_pred, average="macro"))
print(recall_score(y_test, y_pred, average="macro"))
print(f1_score(y_test, y_pred, average="macro"))
print(accuracy_score(y_test, y_pred))
print('') p.append(precision_score(y_test, y_pred, average="macro"))
r.append(recall_score(y_test, y_pred, average="macro"))
f.append(f1_score(y_test, y_pred, average="macro"))
a.append(accuracy_score(y_test, y_pred)) print(p)
print(r)
print(f)
print(a)
print('') print(np.mean(p))
print(np.mean(r))
print(np.mean(f))
print(np.mean(a))

Appscanner实验还原code1的更多相关文章

  1. Appscanner实验还原code3

    # Author: Baozi #-*- codeing:utf-8 -*- import _pickle as pickle from sklearn import ensemble import ...

  2. Appscanner实验还原code2

    import _pickle as pickle from sklearn import svm, ensemble import random from sklearn.metrics import ...

  3. 11.2.0.4rac service_name参数修改

    环境介绍 )客户环境11. 两节点 rac,集群重启后,集群资源一切正常,应用cs架构,连接数据库报错,提示连接对象不存在 )分析报错原因,连接数据库方式:ip:Port/service_name方式 ...

  4. RAC环境修改参数生效测试

    本篇文档--目的:实验测试在RAC环境下,修改数据库参数与单实例相比,需要注意的地方 --举例说明,在实际生产环境下,以下参数很可能会需要修改 --在安装数据库完成后,很可能没有标准化,初始化文档,没 ...

  5. vsftp -samba-autofs

    摘要: 1.FTP文件传输协议,PAM可插拔认证模块,TFTP简单文件传输协议. 注意:iptables防火墙管理工具默认禁止了FTP传输协议的端口号 2.vsftpd服务程序三种认证模式?三种认证模 ...

  6. 【故障处理】ORA-12162 错误的处理

    [故障处理]ORA-12162: TNS:net service name is incorrectly specified 一.1  场景 今天拿到一个新的环境,可是执行sqlplus / as s ...

  7. SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树

    数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...

  8. SDUT 3343 数据结构实验之二叉树四:还原二叉树

    数据结构实验之二叉树四:还原二叉树 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 给定一棵 ...

  9. SDUT-3343_数据结构实验之二叉树四:(先序中序)还原二叉树

    数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定一棵二叉树的先序遍历 ...

随机推荐

  1. 基于位置的服务——百度地图SDK练习

    基于位置的服务所围绕的核心就是要先确定出用户所在的位置.通常有两种技术方式可以实现:一种是通过GPS定位,一种是通过网络定位.Android对这两种定位方式都提供了相应的API支持.但由于众所周知的原 ...

  2. [JOISC2014]挂饰

    嘟嘟嘟 这题其实还是比较好想的,就是有一个小坑点. 首先钩子多的排在前面,然后就是dp了. dp方程就是\(dp[i][j]\)表示到了第\(i\)建物品,还剩\(j\)个挂钩的最大喜悦值.转移就很显 ...

  3. linux普通用户提权操作

    [root@test1 ~]# vim /etc/sudoers ## Allow root to run any commands anywhere root ALL=(ALL) ALLzhouyu ...

  4. 构建企业 YUM仓库

    构建企业 YUM仓库 本地光盘提供基础软件包Base yum缓存提供update软件包 yum缓存提供常用软件包: nginx, zabbix, docker, saltstack 环境准备 系统 I ...

  5. tomcat 改端口 运维最最重要的就是有看日志的习惯

    tomcat一台机器上多实例更改端口需要改三个端口 改tomcat关闭端口 <Server port="9006" shutdown="SHUTDOWN" ...

  6. JDK动态代理(1)-----------new 对象的方式

    //case 1: 直接newHelloWorldImpl helloWorldImpl = new HelloWorldImpl(); //case 2: 反射拿到类之后,通过newInstance ...

  7. Feature Extractor[ResNet v2]

    0. 背景 何凯明大神等人在提出了ResNet网络结构之后,对其做了进一步的分析工作,详细的分析了ResNet 构建块能起作用的本质所在.并通过一系列的实验来验证恒等映射的重要性,并由此提出了新的构建 ...

  8. Generative Adversarial Nets[CAAE]

    本文来自<Age Progression/Regression by Conditional Adversarial Autoencoder>,时间线为2017年2月. 该文很有意思,是如 ...

  9. 使用sql语句比较excel中数据的不同

    使用sql语句比较excel中数据的不同 我所在的项目组是一套物流系统,负责与公司的电商系统进行对接.但是公司的电商系统的省市区的配置和物流系统的省市区的配置有差异,所以需要找到这些差异. 首先找到我 ...

  10. element-ui中 table表格hover 修改背景色

    增加样式级别就行啦   .el-table--enable-row-hover .el-table__body tr:hover>td{ background-color: #212e3e !i ...