-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
35 lines (27 loc) · 944 Bytes
/
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
import matplotlib.pyplot as plt
from models.lstm import create_time_steps
import numpy as np
def plot_train_history(history, title):
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(len(loss))
plt.figure()
plt.plot(epochs, loss, 'b', label='Training loss')
plt.plot(epochs, val_loss, 'r', label='Validation loss')
plt.title(title)
plt.legend()
plt.grid(True)
plt.show()
def multi_step_plot(history, true_future, prediction, step):
plt.figure(figsize=(12, 6))
num_in = create_time_steps(len(history))
num_out = len(true_future)
plt.plot(num_in, np.array(history[:, 0]), label='History')
plt.plot(np.arange(num_out)/step, np.array(true_future), 'gx',
label='True Future')
if prediction.any():
plt.plot(np.arange(num_out)/step, np.array(prediction), 'rx',
label='Predicted Future')
plt.legend(loc='upper left')
plt.grid(True)
return plt