-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
76 lines (64 loc) · 2.26 KB
/
plot.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
import matplotlib.pyplot as plt
import numpy as np
import os
if __name__ == "__main__":
store_root = 'results'
k_list = [20, 50]
lamda_list = [1.0, 0.1, 0.01, 0.001]
k, lamda = 50, 0.01
loss_path = 'loss_rec_k{}_lamda{}.txt'.format(
k, lamda)
loss_path = os.path.join(store_root, loss_path)
loss = []
with open(loss_path, encoding='utf-8') as f:
for line in f:
loss.append(float(line.strip()))
loss = np.array(loss)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(loss, label='$\lambda=${}'.format(lamda))
ax.set_xlabel('epoch')
ax.set_ylabel('loss')
ax.set_title('loss of training data when $k=${}'.format(k))
ax.legend()
plt.show()
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
for i in range(len(k_list)):
loss = [[] for i in range(len(lamda_list))]
for j in range(len(lamda_list)):
loss_path = 'loss_rec_k{}_lamda{}.txt'.format(
k_list[i], lamda_list[j])
loss_path = os.path.join(store_root, loss_path)
loss = []
with open(loss_path, encoding='utf-8') as f:
for line in f:
loss.append(float(line.strip()))
loss = np.array(loss)
ax.plot(loss, label='$k=${}, $\lambda=${}'.format(
k_list[i], lamda_list[j]))
ax.set_xlabel('epoch')
ax.set_ylabel('loss')
# ax.set_title('loss of training data when $k=${}'.format(k_list[i]))
ax.set_title('loss of training data')
ax.legend()
plt.show()
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
for i in range(len(k_list)):
for j in range(len(lamda_list)):
rmse_path = 'RMSE_rec_k{}_lamda{}.txt'.format(
k_list[i], lamda_list[j])
rmse_path = os.path.join(store_root, rmse_path)
rmse = []
with open(rmse_path, encoding='utf-8') as f:
for line in f:
rmse.append(float(line.strip()))
rmse = np.array(rmse)
ax.plot(rmse, label='$k=${}, $\lambda=${}'.format(
k_list[i], lamda_list[j]))
ax.set_xlabel('epoch')
ax.set_ylabel('RMSE')
ax.set_title('RMSE of training data')
ax.legend()
plt.show()