DGA ngram kmeans+TSNE用于绘图
# -*- coding:utf-8 -*- import sys
import re
import numpy as np
from sklearn.externals import joblib
import csv
import matplotlib.pyplot as plt
import os
from sklearn.feature_extraction.text import CountVectorizer
from sklearn import cross_validation
import os
from sklearn.naive_bayes import GaussianNB
from sklearn.cluster import KMeans
from sklearn.manifold import TSNE #处理域名的最小长度
MIN_LEN=10 #随机程度
random_state = 170 def load_alexa(filename):
domain_list=[]
csv_reader = csv.reader(open(filename))
for row in csv_reader:
domain=row[1]
if domain >= MIN_LEN:
domain_list.append(domain)
return domain_list def load_dga(filename):
domain_list=[]
#xsxqeadsbgvpdke.co.uk,Domain used by Cryptolocker - Flashback DGA for 13 Apr 2017,2017-04-13,
# http://osint.bambenekconsulting.com/manual/cl.txt
with open(filename) as f:
for line in f:
domain=line.split(",")[0]
if domain >= MIN_LEN:
domain_list.append(domain)
return domain_list def nb_dga():
x1_domain_list = load_alexa("../data/top-1000.csv")
x2_domain_list = load_dga("../data/dga-cryptolocke-1000.txt")
x3_domain_list = load_dga("../data/dga-post-tovar-goz-1000.txt") x_domain_list=np.concatenate((x1_domain_list, x2_domain_list,x3_domain_list)) y1=[0]*len(x1_domain_list)
y2=[1]*len(x2_domain_list)
y3=[2]*len(x3_domain_list) y=np.concatenate((y1, y2,y3)) print x_domain_list
cv = CountVectorizer(ngram_range=(2, 2), decode_error="ignore",
token_pattern=r"\w", min_df=1)
x= cv.fit_transform(x_domain_list).toarray() clf = GaussianNB()
print cross_validation.cross_val_score(clf, x, y, n_jobs=-1, cv=3) def kmeans_dga():
x1_domain_list = load_alexa("../data/dga/top-100.csv")
x2_domain_list = load_dga("../data/dga/dga-cryptolocke-50.txt")
x3_domain_list = load_dga("../data/dga/dga-post-tovar-goz-50.txt") x_domain_list=np.concatenate((x1_domain_list, x2_domain_list,x3_domain_list))
#x_domain_list = np.concatenate((x1_domain_list, x2_domain_list)) y1=[0]*len(x1_domain_list)
y2=[1]*len(x2_domain_list)
y3=[1]*len(x3_domain_list) y=np.concatenate((y1, y2,y3))
#y = np.concatenate((y1, y2)) #print x_domain_list cv = CountVectorizer(ngram_range=(2, 2), decode_error="ignore",
token_pattern=r"\w", min_df=1)
x= cv.fit_transform(x_domain_list).toarray()
model=KMeans(n_clusters=2, random_state=random_state)
y_pred = model.fit_predict(x)
#print y_pred tsne = TSNE(learning_rate=100)
x=tsne.fit_transform(x)
print x
print x_domain_list for i,label in enumerate(x):
#print label
x1,x2=x[i]
if y_pred[i] == 1:
plt.scatter(x1,x2,marker='o')
else:
plt.scatter(x1, x2,marker='x')
#plt.annotate(label,xy=(x1,x2),xytext=(x1,x2)) plt.show() if __name__ == '__main__':
#nb_dga()
kmeans_dga()
DGA ngram kmeans+TSNE用于绘图的更多相关文章
- php 用于绘图使用的颜色数组
$colorArr = array(0x912CEE, 0x99ff00, 0x312520, 0x801dae, 0x25f8cb, 0xCC3333, 0x808080, 0xa29b7c, 0x ...
- IOS 绘图教程Quartz2D
http://www.cocoachina.com/industry/20140115/7703.html http://www.cnblogs.com/wendingding/p/3803020.h ...
- tsne官方论文代码解读和使用
MLGB,人生就是矫情,充满冲动,充满热恋. tsne的08年的论文看了几遍,发现原理还是蛮简单的,能想到还是不容易(人生的战场是星辰大海,但我们的贡献就是也就是宇宙尘埃) 怎么说呢,现在真的是一个好 ...
- K-means Algorithm
在监督学习中,有标签信息协助机器学习同类样本之间存在的共性,在预测时只需判定给定样本与哪个类别的训练样本最相似即可.在非监督学习中,不再有标签信息的指导,遇到一维或二维数据的划分问题,人用肉眼就很容易 ...
- iOS开发--绘图教程
本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,翻译版本中加入了一些书中未涉及到的内容.希望本文能够对你有所帮助. 本文由海水的味道翻译整理,转载请 ...
- iOS绘图教程 (转,拷贝以记录)
本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,在翻译过程中我加入了一些书中没有涉及到的内容.希望本文能够对你有所帮助. 转自:http://www ...
- MfC基础--绘图基础--win32
1.vc使用的控件分为三类: windows标准控件--MFC对这些进行了再封装 ActiveX 控件 其他MFC控件类 2.CWind是所有窗口的基类 3.GDI也属于一种API,主要用于绘图,(G ...
- iOS绘图教程
本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,翻译版本中加入了一些书中未涉及到的内容.希望本文能够对你有所帮助.(本文由海水的味道翻译整理,转载请 ...
- iOS基础 - Quartz 2D绘图
一.Quartz 2D Quartz 2D是一个二维图形绘制引擎,支持iOS环境和Mac OS X环境. Quartz 2D以PDF的规范为基础的图形库,用来绘制二维文字和图形,允许相同的绘图指令在任 ...
随机推荐
- jQuery幻灯片插件Owl Carousel
简介 Owl Carousel 是一个强大.实用但小巧的 jQuery 幻灯片插件,它具有一下特点: 兼容所有浏览器 支持响应式 支持 CSS3 过度 支持触摸事件 支持 JSON 及自定义 JSON ...
- bzoj3713: [PA2014]Iloczyn(乱搞)
3713: [PA2014]Iloczyn 题目:传送门 题解: 随手一发水题x2 直接离线啊,斐波那契到了第五十个就炒鸡大了 代码: #include<cstdio> #include& ...
- mysqli的简单工具包
mysqli的简单工具包 <?php /** * 连接 * @param string $host * @param string $user * @param string $password ...
- hdoj--1028--Ignatius and the Princess III(母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 利用Spring Hibernate注解packagesToScan的简化自动扫描方式
转自:https://blog.csdn.net/wzygis/article/details/28256045
- HTML5-1、标签
本文只是自己学习HTML5时的一些笔记.希望自己能够学好HTML5. 如果有感兴趣的同学.可以互相学习. 我觉得HTML5在未来的开发中站主导地位. 下面开始学习HTML5. 还是从HTML5标签开始 ...
- Docker运行程序报错 WARNING: IPv4 forwarding is disabled. Networking will not work
WARNING: IPv4 forwarding is disabled. Networking will not work. 第一步:vi /usr/lib/sysctl.d/00-system ...
- 14. Longest Common Prefix[E]最长公共前缀
题目 Write a function to find the longest common prefix string amongst an array of strings. If there i ...
- Solidworks.2016.SP5下载安装破解图文教程
安装此软件一定要断网安装!!!下载完成后解压文件,打开破解文件夹,双击文件夹中的SolidWorksSerialNumbers2016.reg进行注册表注册,如下图. 解压软件安装包(或者将软件安 ...
- 爬虫概念与编程学习之如何爬取视频网站页面(用HttpClient)(二)
先看,前一期博客,理清好思路. 爬虫概念与编程学习之如何爬取网页源代码(一) 不多说,直接上代码. 编写代码 运行 <!DOCTYPE html><html><head& ...