-
Notifications
You must be signed in to change notification settings - Fork 1
/
normalization-test.py
55 lines (49 loc) · 1.26 KB
/
normalization-test.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
from sklearn import preprocessing
import numpy as np
file_name = 'wavelet_yq01-ps-global-42-test'
fin = open(file_name, 'r')
lines = fin.readlines()
fin.close()
data_mat = []
count = 0
for line in lines:
count += 1
if count % 10000 == 0:
print count
row = []
values = line.split(',')[1:]
for k in range(len(values)):
values[k] = float(values[k])
data_mat.append(values)
print 'now begin normalizing...'
scaler_file = 'scaler.data'
fin = open(scaler_file, 'r')
lines = fin.readlines()
scaler = preprocessing.StandardScaler(with_mean = True, with_std = True, copy = False)
fin.close()
means = lines[0].split()
stds = lines[1].split()
for k in range(len(means)):
means[k] = float(means[k])
stds[k] = float(stds[k])
scaler.mean_ = np.array(means)
scaler.std_ = np.array(stds)
data_mat = np.array(data_mat)
data_mat = scaler.transform(data_mat)
print 'now output~'
output_file = 'dnn-' + file_name
fout = open(output_file, 'a')
length = len(data_mat[0])
print 'length', length
count = 0
for row in data_mat:
count += 1
line = '0;0'
for k in range(1, length):
line += ' ' + str(row[k])
line += ';1 ' + str(row[0]) + '\n'
fout.write(line)
if count % 10000 == 0:
print count
fout.flush()
fout.close()