-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp_4_plot.py
176 lines (155 loc) · 5.38 KB
/
exp_4_plot.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 8 13:38:48 2015
@author: thalita
Plots for exp 4 (and 3)
"""
from utils import read_results, plot_metric, plot_metrics, pd_select
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
from itertools import chain
matplotlib.rcParams['ps.useafm'] = True
matplotlib.rcParams['pdf.use14corefonts'] = True
outdir = '/tmp/'
#%%
result = []
for i in range(1,4+1):
path = 'results/exp_%d_results/' % i
result += read_results(path, meanstd=False)
colors = 'bgrcmyk'
result = pd.DataFrame.from_dict(result)
all_metrics = ['P','R','F1','RMSE','MAE']
ir_metrics = ['P','R','F1']
trad_metrics = ['RMSE','MAE']
#%%
select = {'RStype': 'BMFRPrecommender',
'RPtype': 'sparse',
'mincoverage': 1 ,
'threshold': 3 ,
'offlinekNN': 'False',
'neighbortype': 'user',
'algorithm': 'brute',
'metric': 'cosine'}
select_BMF = dict(select)
del select_BMF['RPtype']
select_BMF['RStype'] = 'BMFrecommender'
data = pd_select(result, select_BMF)
data['RStype'] = 'BMFRPrecommender'
data['dimred'] = 1
data['RPtype'] = 'sparse'
tmp = pd.concat((result, data), ignore_index=True)
plot_metrics(all_metrics,
varpar=('dimred', [1, 0.9, 0.8, 0.75, 0.5, 0.25]),
across=('nneighbors', 'num. de vizinhos'),
dataframe=tmp, select=select,
labelfmt='%d%%|D|', labelmul=100,
suptitle='Recomendação BMF+RP esparsa - BMF 100% e limiar 3')
plt.savefig(outdir + 'BMFRP_sparse_dimred_nneighbors.eps')
#%%
select = {'RStype': 'BMFRPrecommender',
'RPtype': 'gaussian',
'mincoverage': 1 ,
'threshold': 3 ,
'offlinekNN': 'False',
'neighbortype': 'user',
'algorithm': 'brute',
'metric': 'cosine'}
select_BMF = dict(select)
del select_BMF['RPtype']
select_BMF['RStype'] = 'BMFrecommender'
data = pd_select(result, select_BMF)
data['RStype'] = 'BMFRPrecommender'
data['dimred'] = 1
data['RPtype'] = 'gaussian'
tmp = pd.concat((result, data), ignore_index=True)
plot_metrics(all_metrics,
varpar=('dimred', [1, 0.9, 0.8, 0.75, 0.5, 0.25]),
across=('nneighbors', 'num. de vizinhos'),
dataframe=tmp, select=select,
labelfmt='%d%%|D|', labelmul=100,
suptitle='Recomendação BMF+RP gaussiana - BMF 100% e limiar 3')
plt.savefig(outdir + 'BMFRP_gaussian_dimred_nneighbors.eps')
#%%
select = {'RStype': 'AvgRatingEnsemble',
'RPtype': 'sparse',
#'mincoverage': 1 ,
'threshold': 3 ,
#'offlinekNN': 'False',
#'neighbortype': 'user',
#'algorithm': 'brute',
#'metric': 'cosine'
}
print(pd_select(result, select))
plot_metrics(all_metrics,
varpar=('nneighbors', [5, 20, 40]),
across=('nprojections', 'num. de projeções'),
dataframe=result, select=select,
labelfmt='%d vizinhos',
suptitle='Recomendação Ensemble BMF+RP esparsa - BMF 100% e limiar 3')
#%%
select = {'RStype': 'AvgRatingEnsemble',
'RPtype': 'sparse',
#'mincoverage': 1 ,
'threshold': 3 ,
#'offlinekNN': 'False',
#'neighbortype': 'user',
#'algorithm': 'brute',
#'metric': 'cosine'
}
select_BMF = dict(select)
del select_BMF['RPtype']
select_BMF['RStype'] = 'BMFrecommender'
select_BMF.update({'mincoverage': 1 ,
'offlinekNN': 'False',
'neighbortype': 'user',
'algorithm': 'brute',
'metric': 'cosine'})
data = pd_select(result, select_BMF)
data['RStype'] = 'AvgRatingEnsemble'
data['RPtype'] = 'sparse'
data['nprojections'] = 0
tmp = pd.concat((result, data), ignore_index=True)
plot_metrics(all_metrics,
varpar=('nprojections', [0, 5, 10, 20, 30]),
across=('nneighbors', 'num. de vizinhos'),
dataframe=tmp, select=select,
labelfmt='%d projeções',
suptitle='Recomendação Ensemble BMF+RP esparsa - BMF 100% e limiar 3')
plt.savefig(outdir + 'BMFRP_avgrating_sparse.eps')
#%%
select = {'RStype': 'AvgRatingEnsemble',
'RPtype': 'gaussian',
#'mincoverage': 1 ,
'threshold': 3 ,
#'offlinekNN': 'False',
#'neighbortype': 'user',
#'algorithm': 'brute',
#'metric': 'cosine'
}
print(pd_select(result, select))
plot_metrics(all_metrics,
varpar=('nneighbors', [20]),
across=('nprojections', 'num. de projeções'),
dataframe=result, select=select,
labelfmt='%d vizinhos',
suptitle='Recomendação Ensemble BMF+RP gaussiana - BMF 100% e limiar 3')
plt.savefig(outdir + 'BMFRP_avgrating_gaussian.eps')
#%%
select = {'RStype': 'AvgRatingEnsemble',
'nneighbors': 20,
#'mincoverage': 1 ,
'threshold': 3 ,
#'offlinekNN': 'False',
#'neighbortype': 'user',
#'algorithm': 'brute',
#'metric': 'cosine'
}
print(pd_select(result, select))
plot_metrics(all_metrics,
varpar=('RPtype', ['sparse', 'gaussian']),
across=('nprojections', 'num. de projeções'),
dataframe=result, select=select,
labelfmt='RP %s',
suptitle='Recomendação Ensemble BMF+RP esparsa vs. RP gaussiana - BMF 100% e limiar 3')