forked from RemexHu/BandwidthPrediction-LSTM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test_norm.py
77 lines (51 loc) · 2.17 KB
/
Test_norm.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 pandas
import matplotlib.pyplot as plt
import numpy
import matplotlib.pyplot as plt
import pandas
import math
import keras
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Dropout
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
import numpy as np
#file = pandas.read_csv('test_sim_traces/norway_bus_1', names = ["band"], sep = '\t')
#file = pandas.read_csv('test_sim_traces/norway_tram_1', names = ["band"], sep = '\t')
#file = pandas.read_csv('test_sim_traces/norway_train_1', names = ["band"], sep = '\t')
file = pandas.read_csv('test_sim_traces/norway_car_1', names = ["band"], sep = '\t')
#file = pandas.read_csv('test_sim_traces/norway_metro_1', names = ["band"], sep = '\t')
#file = pandas.read_csv('test_sim_traces/norway_ferry_1', names = ["band"], sep = '\t')
dataset = file["band"][:]
dataset = dataset[:]
dataset = np.asarray(dataset)
dataset = np.vstack(dataset)
model_mse = keras.models.load_model('model_mse_all_norm_cmplx2.h5')
model_mse.summary()
scaler = MinMaxScaler(feature_range=(0, 1))
dataset = scaler.fit_transform(dataset)
def create_dataset(dataset, look_back=1):
dataX, dataY = [], []
for i in range(len(dataset) - look_back - 1):
a = dataset[i:(i + look_back), 0]
dataX.append(a)
dataY.append(dataset[i + look_back, 0])
return numpy.array(dataX), numpy.array(dataY)
look_back = 1
testX, testY = create_dataset(dataset, look_back)
testX = numpy.reshape(testX, (testX.shape[0], testX.shape[1], 1))
testY_inverse = scaler.inverse_transform([testY])
testPredict = model_mse.predict(testX)
testPredict_mse = scaler.inverse_transform(testPredict)
testPredict = np.hstack(testPredict)
print(testY.shape, testPredict.shape)
testScore = math.sqrt(mean_squared_error(testY_inverse[0], testPredict_mse[:,0]))
#testScore = math.sqrt(mean_squared_error(testY, testPredict))
print('Test Score: %.2f RMSE' % (testScore))
plt.figure(figsize=(25,9))
plt.plot(scaler.inverse_transform(dataset))
plt.plot(testPredict_mse)
plt.savefig('/home/runchen/Pictures/all_norm_simple_ferry_' + str(round(testScore, 2)) +'.png')
plt.show()