Skip to content

Commit f99bbeb

Browse files
4月16日 组会之前
1 parent adfe9c3 commit f99bbeb

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

序列预测/PCA去趋势化/dev2/main2.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ def use_pca(dataset):
137137
# lstm的hyper-parameter
138138
hidden_size = 400
139139
layer_num = 1
140-
max_epoch = int(2000 * 0.5)
141-
dropout_keep_rate = 0.5
140+
max_epoch = int(3000)
141+
dropout_keep_rate = 0.7
142142

143143
# 根据输入数据来决定,train_num训练集大小,input_size输入维度
144144
train_num, time_step_size, input_size = train_x.shape # sahpe :12 * 2 *480
@@ -185,19 +185,15 @@ def get_metrics(y, pred_y):
185185
rmse = np.sqrt(np.mean(np.square(y - pred_y)))
186186
return mre, mae, rmse
187187

188-
def cal_mre(y,y_pre):
189-
y[y < 0.1] = 0.1
190-
diff = np.abs(y-y_pre)
191-
mre = np.mean(diff/y)
192-
print("cal mre is : ", mre)
193188

194-
def print_to_console(i, train_y ,train_y_pred,flag_istrain):
189+
def print_to_console(i, train_y ,train_y_pred,flag_istrain,isshow):
195190
train_y_pred_real = train_y_pred * (y_max - y_min) + y_min # 反归一化
196191
train_y_real = train_y * (y_max - y_min) + y_min # train_y 是真实的y值,堆train_y 进行反归一化
197192

198-
plt.plot(range(dnum), train_y_real[0], 'b-',label='true') # 实际用蓝色
199-
plt.plot(range(dnum), train_y_pred_real[0], 'r-',label='prediction') # 预测用红色
200-
plt.show()
193+
if(isshow==1):
194+
plt.plot(range(dnum), train_y_real[0], 'b-',label='true') # 实际用蓝色
195+
plt.plot(range(dnum), train_y_pred_real[0], 'r-',label='prediction') # 预测用红色
196+
plt.show()
201197
"""
202198
if (flag_istrain==1):
203199
plt.savefig("train"+str(i)+".png")
@@ -215,16 +211,16 @@ def print_to_console(i, train_y ,train_y_pred,flag_istrain):
215211
for i in range(1, max_epoch + 1):
216212
feed_dict = {x_input: train_x, y_real: train_y, keep_prob: dropout_keep_rate, batch_size: train_num}
217213
sess.run(train_op, feed_dict=feed_dict)
218-
if i % 100 == 0:
214+
if i % 200 == 0:
219215
feed_dict = {x_input: train_x, y_real: train_y, keep_prob: 1.0, batch_size: train_num}
220216
train_y_pred = sess.run(y_pred, feed_dict=feed_dict)
221217
#print ("train_y_pred : ",train_y_pred.shape) #(9,480)
222-
print_to_console(i,train_y, train_y_pred,1)
223-
if i % 100 ==0:
218+
print_to_console(i,train_y, train_y_pred,1,0)
219+
if i % 200 ==0:
224220
feed_dict = {x_input: test_x, y_real: test_y, keep_prob: 1.0, batch_size: test_len}
225221
test_y_pred = sess.run(y_pred, feed_dict=feed_dict)
226222
#print ("test_y_pred : ",test_y_pred.shape) #(3,480)
227-
print_to_console(i, test_y,test_y_pred,0)
223+
print_to_console(i, test_y,test_y_pred,0,0)
228224

229225
#to-do
230226
y_main = dataset_main[0][time_step:days, :] # y_main的主成分[2~14] shape 12 * 2 * 480

序列预测/PCA去趋势化/show.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ def show2(main_x,rest_x):
2626
plt.plot(item)
2727
plt.show()
2828

29+
def show_index(arr,index):
30+
plt.xlabel("Index of time")
31+
plt.ylabel("Traffic volume")
32+
plt.plot(arr[index])
33+
plt.show()
34+
plt.close()
35+
2936
if __name__=="__main__":
3037
arr = myload("dump_arr_9-13.txt")
3138
main_x = myload("dump_main_x_9-13.txt")
3239
rest_x = myload("dump_rest_x_9-13.txt")
3340
show1(arr)
41+
show1(main_x)
42+
show1(rest_x)
3443
show2(main_x,rest_x)
130 KB
Loading

0 commit comments

Comments
 (0)