-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_plots.py
64 lines (52 loc) · 1.79 KB
/
generate_plots.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
# -*- coding: utf-8 -*-
import os
import matplotlib.pyplot as plt
import seaborn as sns
from pykeen.datasets import datasets
from utils import read_experiment_collation
HERE = os.path.abspath(os.path.dirname(__file__))
PLOTS_DIRECTORY = os.path.join(HERE, 'plots')
os.makedirs(PLOTS_DIRECTORY, exist_ok=True)
sns.set_style('whitegrid')
def make_dataset_plots(m: str = 'metrics.hits_at_k.avg.10'):
u = {
m: ('hits_at_10', 'Hits@10', {}),
'times.training': ('time', 'Time (s)', {'xscale': 'log'}),
}
df = read_experiment_collation()
df['dataset'] = df['dataset'].map(lambda s: datasets[s].__name__)
for x, (op, label, setters) in u.items():
g = sns.catplot(
x=x,
y='model',
data=df,
col='dataset',
col_wrap=2,
kind='bar',
order=sorted(df['model'].unique()),
)
g.set_titles(template='{col_name}', size=20)
g.set_ylabels('')
g.set_xlabels(label)
g.set(**setters)
g.fig.tight_layout()
g.savefig(os.path.join(PLOTS_DIRECTORY, f'overview_{op}.pdf'))
g.savefig(os.path.join(PLOTS_DIRECTORY, f'overview_{op}.png'), dpi=300)
plt.close(g.fig)
g = sns.FacetGrid(
data=df,
col='dataset',
col_wrap=2,
hue='model',
hue_order=sorted(df['model'].unique()),
legend_out=True,
)
g.map(sns.scatterplot, 'times.training', m, alpha=0.5)
g.set_titles(template='{col_name}')
g.set(xscale='log', xlabel='Time (s)', ylabel='Hits@10')
g.fig.tight_layout()
g.savefig(os.path.join(PLOTS_DIRECTORY, f'overview_scatter.pdf'))
g.savefig(os.path.join(PLOTS_DIRECTORY, f'overview_scatter.png'), dpi=300)
plt.close(g.fig)
if __name__ == '__main__':
make_dataset_plots()