@@ -137,8 +137,8 @@ def use_pca(dataset):
137
137
# lstm的hyper-parameter
138
138
hidden_size = 400
139
139
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
142
142
143
143
# 根据输入数据来决定,train_num训练集大小,input_size输入维度
144
144
train_num , time_step_size , input_size = train_x .shape # sahpe :12 * 2 *480
@@ -185,19 +185,15 @@ def get_metrics(y, pred_y):
185
185
rmse = np .sqrt (np .mean (np .square (y - pred_y )))
186
186
return mre , mae , rmse
187
187
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 )
193
188
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 ):
195
190
train_y_pred_real = train_y_pred * (y_max - y_min ) + y_min # 反归一化
196
191
train_y_real = train_y * (y_max - y_min ) + y_min # train_y 是真实的y值,堆train_y 进行反归一化
197
192
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 ()
201
197
"""
202
198
if (flag_istrain==1):
203
199
plt.savefig("train"+str(i)+".png")
@@ -215,16 +211,16 @@ def print_to_console(i, train_y ,train_y_pred,flag_istrain):
215
211
for i in range (1 , max_epoch + 1 ):
216
212
feed_dict = {x_input : train_x , y_real : train_y , keep_prob : dropout_keep_rate , batch_size : train_num }
217
213
sess .run (train_op , feed_dict = feed_dict )
218
- if i % 100 == 0 :
214
+ if i % 200 == 0 :
219
215
feed_dict = {x_input : train_x , y_real : train_y , keep_prob : 1.0 , batch_size : train_num }
220
216
train_y_pred = sess .run (y_pred , feed_dict = feed_dict )
221
217
#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 :
224
220
feed_dict = {x_input : test_x , y_real : test_y , keep_prob : 1.0 , batch_size : test_len }
225
221
test_y_pred = sess .run (y_pred , feed_dict = feed_dict )
226
222
#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 )
228
224
229
225
#to-do
230
226
y_main = dataset_main [0 ][time_step :days , :] # y_main的主成分[2~14] shape 12 * 2 * 480
0 commit comments