-
Notifications
You must be signed in to change notification settings - Fork 36
/
utils.py
47 lines (37 loc) · 1.32 KB
/
utils.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
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# Seaborn options
sns.set(style="whitegrid", font_scale=1.4)
def plot_training_curves(history, figsize=(12, 5)):
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=figsize)
ax1.plot(history.history['accuracy'])
ax1.plot(history.history['val_accuracy'])
ax1.set_title('Model accuracy')
ax1.set_ylabel('Accuracy')
ax1.set_xlabel('Epoch')
ax1.legend(['Train', 'Val'], loc='upper left')
ax2.plot(history.history['loss'])
ax2.plot(history.history['val_loss'])
ax2.set_title('Model loss')
ax2.set_ylabel('Loss')
ax2.set_xlabel('Epoch')
ax2.legend(['Train', 'Val'], loc='upper left')
return fig
def print_confusion_matrix(confusion_matrix, class_names, figsize=(10, 7), fontsize=14):
df_cm = pd.DataFrame(
confusion_matrix, index=class_names, columns=class_names,
)
fig = plt.figure(figsize=figsize)
heatmap = sns.heatmap(df_cm, annot=True, fmt="d", cmap="YlGnBu")
heatmap.yaxis.set_ticklabels(
heatmap.yaxis.get_ticklabels(), rotation=0,
ha='right', fontsize=fontsize
)
heatmap.xaxis.set_ticklabels(
heatmap.xaxis.get_ticklabels(), rotation=45,
ha='right', fontsize=fontsize
)
plt.ylabel('True label')
plt.xlabel('Predicted label')
return fig