-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_softmax_classification_performance.py
More file actions
69 lines (52 loc) · 1.7 KB
/
plot_softmax_classification_performance.py
File metadata and controls
69 lines (52 loc) · 1.7 KB
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
# -*- coding: utf-8 -*-
'''
Created on Fri Nov 9 09:03:03 2018
@author:
Visa Suomi
Turku University Hospital
November 2018
@description:
This function is used for plotting the performance metrics from a trained
Keras model
'''
#%% import necessary libraries
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
#%% define function
def plot_softmax_classification_performance(model, losses, cm_training, cm_validation):
# training logloss
f1 = plt.figure(figsize = (18, 4))
plt.subplot(1, 3, 1)
plt.title('Training and validation loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
if model == 'keras':
plt.plot(losses.epoch, np.array(losses.history['loss']),
label = 'Training')
plt.plot(losses.epoch, np.array(losses.history['val_loss']),
label = 'Validation')
if model == 'xgboost':
plt.plot(np.array(list(losses['training'].values())[0]), label = 'Training')
plt.plot(np.array(list(losses['validation'].values())[0]), label = 'Validation')
plt.grid()
plt.legend()
plt.legend()
plt.grid()
# confusion matrix (training)
# plt.figure()
plt.subplot(1, 3, 2)
ax = sns.heatmap(cm_training, cmap = 'bone_r')
ax.set_aspect(1)
plt.title('Confusion matrix (training)')
plt.ylabel('True class')
plt.xlabel('Predicted class')
# confusion matrix (validation)
# plt.figure()
plt.subplot(1, 3, 3)
ax = sns.heatmap(cm_validation, cmap = 'bone_r')
ax.set_aspect(1)
plt.title('Confusion matrix (validation)')
plt.ylabel('True class')
plt.xlabel('Predicted class')
return f1