-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoriginal.py
More file actions
59 lines (42 loc) · 1.28 KB
/
original.py
File metadata and controls
59 lines (42 loc) · 1.28 KB
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
import scipy.stats as st
import math,time
from sklearn import preprocessing
import numpy as np
class Original:
#def __init__(self):
# super(Original, self).__init__()
def run(self):
beg=time.time()
def dataPrepare(item):
''' get the values, remove the categorical data'''
a=item.split(',')
label=a[len(a)-1].split('\n')[0]
data=a[5:len(a)-1]#removing IPsrc,IPdst,portsrc,portdsc,proto
return data
def calculate(dataset):
original=np.asfarray(dataset)
original=original.tolist()
X_normalized = preprocessing.normalize(original, norm='max')
lower, upper = -3.09, 3.09
X_normed = [lower + (upper - lower) * x for x in X_normalized]
return X_normalized
np.set_printoptions(precision=3)
np.set_printoptions(suppress=True,formatter={'float_kind':'{:f}'.format})
files=open('classes-17-end.out','r')
lines=files.readlines()
self.batch=[]
batch=self.batch
for i in lines:
batch.append(dataPrepare(i))
saida = open("Original-classes-17-norm.out", "w")
salida=calculate(batch)
''' to write in file'''
for k in salida:
tmp = []
for l in k:
tmp.append(str(l))
linhaSaida = ",".join(tmp)
saida.write(linhaSaida+"\n")
end=time.time()-beg
saida.write(str('processing time : '+str(end)))
return calculate(batch)