-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsummary.py
142 lines (124 loc) · 3.4 KB
/
summary.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""from glob import glob
def read(fn):
f = open(fn)
t = f.read()
f.close()
return t
combined = ["output_id,output"]
for taski in range(419):
ids = set()
cands = []
for fn in glob("output/answer_%d_*.csv"%taski):
#if not '_13.' in fn and not '_3.' in fn: continue
t = read(fn).strip().split('\n')
ids.add(t[0])
for cand in t[1:]:
img, score = cand.split()
cands.append((float(score), img))
assert(len(ids) == 1)
id = ids.pop()
seen = set()
cands.sort(reverse=True)
best = []
for cand in cands:
score, img = cand
if not img in seen:
seen.add(img)
best.append(img)
if len(best) == 3:
break
if not best: best.append('|0|')
combined.append(id+','+' '.join(best))
outf = open('submission_part.csv', 'w')
for line in combined:
print(line, file=outf)
outf.close()
exit(0)
"""
inds = range(0,419)
inds = list(inds)
compressed = ''
memories = []
times = []
def read(fn):
try:
f = open(fn, 'r')
t = f.read()
f.close()
return t
except:
return ''
score = [0,0,0,0]
for i in inds:
t = read('store/%d_out.txt'%i)
line = t[t.index('Task #'):].split('\n')[0]
#print(line)
if line.count('Correct'): s = 3
elif line.count('Candidate'): s = 2
elif line.count('Dimensions'): s = 1
else: s = 0
score[s] += 1
compressed += str(s)
t = read('store/tmp/%d_err.txt'%i)
if t:
memories.append([int(t.split('maxresident')[0].split(' ')[-1]), i])
m,s = t.split('elapsed')[0].split(' ')[-1].split(':')
times.append([float(m)*60+float(s), i])
for i in range(3,0,-1):
score[i-1] += score[i]
print(compressed)
print()
print("Total: % 4d" % score[0])
print("Size : % 4d" % score[1])
print("Cands: % 4d" % score[2])
print("Correct:% 3d"% score[3])
memories.sort(reverse=True)
it = 0
for mem,i in memories:
print("%d : %.1f GB"%(i, mem/2**20))
it += 1
if it == 5: break
print()
times.sort(reverse=True)
it = 0
for secs,i in times:
print("%d : %.1f s"%(i, secs))
it += 1
if it == 5: break
exit(0)
for i in inds:
t = read('store/tmp/%d_err.txt'%i)
if t:
print(t.count("Features: 4"))
import numpy as np
from sklearn import cross_validation, linear_model
from math import log10
#Estimate times
x, y = [], []
for i in inds:
t = read('store/tmp/%d_err.txt'%i)
if t:
m,s = t.split('elapsed')[0].split(' ')[-1].split(':')
y.append(float(m)*60+float(s))
f = [float(i) for i in t.split('Features: ')[-1].split('\n')[0].split(' ')]
p = []
print(f, y[-1])
for i in range(len(f)):
for j in range(i):
p.append(f[i]*f[j])
p.append(f[i])
p = [f[0], f[3], f[0]*f[3]]
x.append(p)
"""loo = cross_validation.LeaveOneOut(len(y))
regr = linear_model.LinearRegression()
scores = cross_validation.cross_val_score(regr, x, y, scoring='neg_mean_squared_error', cv=loo,)
print(10**((-scores.mean())**.5))"""
model = linear_model.LinearRegression()
model.fit(x, y)
r_sq = model.score(x, y)
loo = cross_validation.LeaveOneOut(len(y))
scores = cross_validation.cross_val_score(model, x, y, scoring='neg_mean_squared_error', cv=loo,)
print(((-scores.mean())**.5))
print('coefficient of determination:', r_sq)
print('intercept:', model.intercept_)
print('slope:', model.coef_)