-
Notifications
You must be signed in to change notification settings - Fork 38
/
plots.py
78 lines (58 loc) · 2.19 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import matplotlib as mpl
# do not use Qt/X that require $DISPLAY, must be called before importing pyplot
mpl.use('Agg')
import matplotlib.pyplot as plt
import seaborn as sns
def plot_learning_curves_separate(df):
fig, axes = plt.subplots(ncols=2, figsize=(15, 5))
sns.despine()
fig.suptitle('Learning curves')
for ax, metric, color in zip(axes, ['error', 'loss'], ['r', 'b']):
for split, lw in zip(['train', 'valid'], [1, 2]):
ax.plot(df['%s_%s' % (split,metric)], color=color, lw=lw, label=split)
ax.set_title(metric)
ax.set_xlabel('epoch')
ax.set_ylabel(metric)
ax.grid(True)
ax.legend()
# error
axes[0].set_ylim(0, 1)
fig.tight_layout()
return fig, axes
def plot_learning_curves_together(df):
fig, ax1 = plt.subplots(figsize=(10, 5))
sns.despine()
ax2 = ax1.twinx()
axes = (ax1, ax2)
fig.suptitle('Learning curves')
for ax, metric, color in zip(axes, ['error', 'loss'], ['r', 'b']):
for split, line_style in zip(['train', 'valid'], ['--', '-']):
ax.plot(df['%s_%s' % (split,metric)], color + line_style, label=split)
ax.set_xlabel('epoch')
ax.set_ylabel(metric, color=color)
ax.legend()
return fig, axes
def plot_confusion_matrix(cm, labels, split):
fig, ax = plt.subplots()
fig.suptitle('Confusion matrix (%s)' % split)
ax.grid(False)
im = ax.imshow(cm, interpolation='nearest', cmap=plt.cm.Blues)
fig.colorbar(im)
tick_marks = list(range(len(labels)))
ax.set_xticks(tick_marks)
ax.set_xticklabels(labels, rotation=45)
ax.set_yticks(tick_marks)
ax.set_yticklabels(labels)
ax.set_ylabel('True label')
ax.set_xlabel('Predicted label')
fig.tight_layout()
return fig, ax
def plot_error_by_midi_bin(df, split):
fig, axes = plt.subplots(ncols=2, figsize=(15, 5))
fig.suptitle('Error (absolute, relative) by pitch bins')
df[['correct', 'incorrect']].plot(
kind='bar', stacked=True, color=['green', 'red'], ax=axes[0])
df[['correct_perc', 'incorrect_perc']].plot(
kind='bar', stacked=True, color=['green', 'red'], ax=axes[1])
fig.tight_layout()
return fig, axes