/
submitter.py
49 lines (40 loc) · 1.17 KB
/
submitter.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
from data import Data
from classifier import Classifier
from score import score
from time import time
from blackbox_preprocess import BlackboxPreprocess
from sklearn import preprocessing
def log(info):
f = file('submission.txt', 'w+')
f.write(str(info))
f.close()
def submission(preds):
out = ""
for p in preds:
out += str(p) + "\n"
log(out)
data, targets = Data.data()
print "training data: ", len(data)
test = Data.test()
print "test data: ", len(test)
data = data + test
print "all data: ", len(data)
# preprocessing
start = time()
matrix = BlackboxPreprocess.to_matrix(data)
print matrix.shape
matrix = BlackboxPreprocess.scale(matrix)
#matrix = BlackboxPreprocess.polynomial(matrix, 2)
matrix = preprocessing.normalize(matrix, norm='l2')
min_max_scaler = preprocessing.MinMaxScaler(feature_range=(-1.,1.))
matrix = min_max_scaler.fit_transform(matrix)
#matrix = BlackboxPreprocess.norm(matrix)
print matrix.shape
data = matrix.tolist()
# split training and test data
test_data = data[1000:]
data, targets = data[:1000], targets[:1000]
# testing
preds = Classifier.preds(data, targets, test_data, [])
print "Duration: ", time() - start
submission(preds)