-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgera_tabela.py
83 lines (71 loc) · 2.75 KB
/
gera_tabela.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
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 22 18:20:41 2016
@author: thalita
script para gerar tabela com tempos e performance no latex
Para um so model_size. Repete a tabela pra outros.
RS Tempo Treinam. Tempo Rec. P@20 RMSE
nome xxx $\pm$ zz ...
"""
import expdb
import pandas as pd
import config
import numpy as np
configs = [
config.BMF5fold,
config.BMFLSH5fold,
config.BMFRP5fold,
config.BMFRPLSH5fold,
config.MixedConfig(config.BMFRP5fold.copy(), config.LinReg.copy(),
'dim_red', [str(n) for n in np.arange(0.1,0.31,0.02)])]
# for i, _ in enumerate(configs):
# configs[i].set_par('database', 'TestDB')
edb = expdb.ExperimentDB()
def make_section():
global configs, fields, fmts, table
for conf in configs:
eid = edb.get_id(conf)
if eid is not None:
line = ''
for i_f, f in enumerate(fields):
if i_f == 0:
s = ''
if pd.notnull(edb.db['Ens_type'].loc[eid].values[0]):
s += edb.db['Ens_type'].loc[eid].values[0] + ' '
s = s.replace('Ensemble', ' Ensemble')\
.replace('LinReg', 'Lin. Reg.')\
.replace('Rating', ' Rating')\
.replace('List', ' List')\
.replace('WAvg', 'W. Avg.')\
s += edb.db[f].loc[eid].values[0].replace('recommender', '')
if edb.db['algorithm'].loc[eid].values[0] == 'LSH':
s += '+LSH'
else:
if f.find('train_time') > -1 and conf.is_MF:
train = edb.db[f].loc[eid].values
MF = edb.db[f.replace('train', 'MF')].loc[eid].values
v = np.nansum(np.vstack([train, MF]), axis=0)
else:
v = edb.db[f].loc[eid]
s = fmts[i_f]%(np.nanmean(v)) + ' $\pm$ ' + \
fmts[i_f]%(np.nanstd(v))
line += s + ' & '
line = line[:-2]
line += '\\\\ \n'
table += line
else:
print('Experiment not found', conf.as_dict())
#%%
fields = ['RS_type', 'train_time', 'rec_time', 'P@20_valid', 'RMSE_valid']
fmts = [None, '%d', '%d', '%0.3f', '%0.3f']
table = '\hline \n'
for model_size in ['1','0.5','0.3']:
table += '\multicolumn{5}{|c|}{$l=' + (1-int(float(model_size)))*model_size \
+ '|U|$} \\\\\hline\n'
for i_c, c in enumerate(configs):
configs[i_c].set_par('model_size', model_size)
make_section()
table += '\hline \n'
header = '\hline\nMétodo & Tempo treinamento & Tempo recomendação & P@20 & RMSE\\\\\n'
table = header + table
print(table)