-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdataset_plotter.py
executable file
·71 lines (68 loc) · 1.78 KB
/
dataset_plotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
import plotly
import plotly.graph_objs as go
from .string_classifier import generate_training_set
def generate_3d_scatterplot(api_key_files, generic_text_files, dump_file):
mat, strings = generate_training_set(api_key_files, generic_text_files, True)
apis = []
apis_text = []
text = []
text_text = []
for row, string in zip(mat, strings):
if row[3] == 1:
apis_text.append(string)
apis.append(row)
else:
text_text.append(string)
text.append(row)
apis = np.array(apis)
text = np.array(text)
api_trace = go.Scatter3d(
name="Api-Key",
x=apis[:, 0],
y=apis[:, 1],
z=apis[:, 2],
text=apis_text,
mode='markers',
marker=dict(
size=3,
line=dict(
color='rgba(0, 0, 255, 0.14)',
width=0.5
),
opacity=0.6
)
)
text_trace = go.Scatter3d(
name="Text",
x=text[:, 0],
y=text[:, 1],
z=text[:, 2],
text=text_text,
mode='markers',
marker=dict(
size=3,
line=dict(
color='rgba(255, 0, 0, 0.14)',
width=0.5
),
opacity=0.6
)
)
data = [api_trace, text_trace]
layout = go.Layout(
title="Dataset",
margin=dict(
l=1,
r=1,
b=1,
t=1
),
scene=dict(
xaxis=dict(title="entropy"),
yaxis=dict(title="sequentiality"),
zaxis=dict(title="gibberish"))
)
fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig, filename=dump_file, auto_open=False)
print("Saved to {0}".format(dump_file))