-
Notifications
You must be signed in to change notification settings - Fork 2
/
visualize.py
executable file
·83 lines (73 loc) · 3 KB
/
visualize.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
#!/usr/bin/env python3
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
from scipy import stats
import sys
import os.path as osp
# data['x'] = data['year'] + data['epoch'] / data.epoch.values.max()
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('data', nargs='+')
parser.add_argument('--style', default=None)
parser.add_argument('--hue', default=None)
parser.add_argument('--markers', default=None)
parser.add_argument('--row', default=None)
parser.add_argument('--col', default=None)
parser.add_argument('--vertlines', default=None)
parser.add_argument('--ci', action='store_true', default=False, help="Plot CI regions")
parser.add_argument('--sd', action='store_true', default=False, help="Plot SD regions")
parser.add_argument('--nosharey', action='store_false', default=True, dest='sharey', help="Plot SD regions")
parser.add_argument('--aspect', type=float, default=1.,help="Aspect * height = width of each facet")
parser.add_argument('--save', default=None)
args = parser.parse_args()
if args.sd and args.ci:
raise ValueError("Plot 95% CI or SD as regions? both is not possible")
elif args.sd:
ci = 'sd'
elif args.ci:
ci = 95
else:
ci = None
print("Using data:", args.data[0])
data = pd.read_csv(args.data[0])
print("N =",len(data))
for path in args.data[1:]:
print("Adding data:", path)
add_data = pd.read_csv(path)
data = pd.concat([data, add_data], axis=0, ignore_index=True)
print("N =",len(data))
data['retrain'] = data.annual_epochs.map(bool)
data['window size %RF'] = data.history.map({1: '25%', 3: '50%', 4: '50%', 6: '75%', 8: '75%', 21: '100%', 25: '100%'})
# data.dataset = data.dataset.map({'7dc': 'pharmabio', 'dblp-graph': 'dblp-easy', 'dblp-graph-hard': 'dblp-hard'})
theplot = sns.relplot(x='year',
y='accuracy',
kind='line',
data=data,
row=args.row,
col=args.col,
markers=args.markers,
style=args.style,
hue=args.hue,
ci=ci,
aspect=args.aspect,
facet_kws={'sharex':False, 'sharey':args.sharey},
palette='colorblind')
# sns.relplot(x='year', y='accuracy', kind='line', data=data, hue="n_layers", style="n_hidden")
if args.vertlines:
def plot_vline(x, **kwargs):
plt.axvline(x=x, ymin=0., ymax=1., linestyle='dashed', zorder=-1,
c='r')
minyear, maxyear = data.year.min(), data.year.max()
acc_range = [data.accuracy.min(), data.accuracy.max()]
with open(args.vertlines, 'r') as f:
ts = [int(line.strip()) for line in f]
ts = [t for t in ts if t >= minyear and t <= maxyear]
for t in ts:
theplot = theplot.map_dataframe(plot_vline, x=t).add_legend().set_axis_labels("year", "accuracy")
if args.save:
plt.savefig(args.save)
else:
plt.savefig(osp.splitext(args.data[0])[0] + '.png')