def on_epoch_begin(self, epoch, logs={}): lr = K.get_value(model.optimizer.lr) print("current learning rate is {}".format(lr)) pred = model.predict(x_test) predict_all = pred.flatten() truth_all = y_test.flatten() mape = eleceval.calcMAPE(predict_all, truth_all) mae = eleceval.calcMAE(predict_all, truth_all) mse = eleceval.calcMSE(predict_all, truth_all) rmse = eleceval.calcRMSE(predict_all, truth_all) r_2 = eleceval.r2(predict_all, truth_all) print("After %d training step(s)," "on test data MAPE = %.4f,MAE = %.4f,MSE = %.4f,RMSE = %.4f,R2 = %.4f"\ % (epoch, mape,mae,mse,rmse,r_2)) if mape <= self.mape_flag: self.mape_flag = mape #两个ndarray列合并 #y_con = np.concatenate((truth_all, predict_all), axis=1) truth_all_reshape = np.reshape(truth_all, [-1, 1]) predict_all_reshape = np.reshape(predict_all, [-1, 1]) y_con = np.concatenate((truth_all_reshape, predict_all_reshape), axis=1) #输出真实值和预测值 y_out = pd.DataFrame(y_con, columns=["true_data", "pre_data"]) y_out.to_csv('./result_929_3cluster/steps=%d-MAPE=%.4f,MAE = %.4f,MSE = %.4f,RMSE = %.4f,R2 = %.4f.csv'\ % (epoch,mape,mae,mse,rmse,r_2))
def on_epoch_begin(self, epoch, logs={}): lr = K.get_value(model.optimizer.lr) print("current learning rate is {}".format(lr)) pred = model.predict({'input_layer':x_test, 'aux_input':aux_x_test}) pred = np.array(pred) predict_all = pred.flatten() truth_all = np.array(y_test) truth_all = truth_all.flatten() maape = eleceval.calcMaape(predict_all,truth_all) mape = eleceval.calcMAPE(predict_all,truth_all) mae = eleceval.calcMAE(predict_all,truth_all) mse = eleceval.calcMSE(predict_all,truth_all) rmse = eleceval.calcRMSE(predict_all,truth_all) r_2 = eleceval.r2(predict_all,truth_all) print("After %d training step(s)," "on test data MAAPE = %.4f,MAPE = %.4f,MAE = %.4f,MSE = %.4f,RMSE = %.4f,R2 = %.4f"\ % (epoch, maape,mape,mae,mse,rmse,r_2)) if maape <= self.maape_flag: self.maape_flag = maape #concatenate two arrays truth_all_reshape=np.reshape(truth_all,[-1,1]) predict_all_reshape=np.reshape(predict_all,[-1,1]) y_con = np.concatenate((truth_all_reshape, predict_all_reshape), axis=1) #Print true value and predicted value y_out = pd.DataFrame(y_con, columns=["true_data","pre_data"]) y_out.to_csv('steps=%d-MAAPE=%.4f.csv'\ % (epoch, maape))
def on_epoch_begin(self, epoch, logs={}): # print(f'x_test[0:1] = {x_test[0:1]}.') # print(f'y_test[0:1] = {y_test[0:1]}.') # print(f'pred = {self.model.predict(x_test[0:1])}.') lr = K.get_value(model.optimizer.lr) print("current learning rate is {}".format(lr)) pred = model.predict(x_test) pred = pred[:, 239, :] print('pred.shape:') print(pred.shape) print('y_test.shape:') print(y_test.shape) predict_all = pred.flatten() truth_all = y_test.flatten() ''' pred_train = model.predict(x_train) predict_train = pred_train.flatten() truth_train = y_train.flatten() mape_train = eleceval.calcMAPE(predict_train,truth_train) mae_train = eleceval.calcMAE(predict_train,truth_train) mse_train = eleceval.calcMSE(predict_train,truth_train) rmse_train = eleceval.calcRMSE(predict_train,truth_train) r_2_train = eleceval.r2(predict_train,truth_train) print("After %d training step(s)," "on test data MAPE_train = %.4f,MAE_train = %.4f,MSE_train = %.4f,RMSE_train = %.4f,R2_train = %.4f"\ % (i*10, mape_train,mae_train,mse_train,rmse_train,r_2_train)) ''' a1 = pred a2 = y_test a = pinball_score(a1, a2, 9) mape = eleceval.calcMAPE(predict_all, truth_all) mae = eleceval.calcMAE(predict_all, truth_all) mse = eleceval.calcMSE(predict_all, truth_all) rmse = eleceval.calcRMSE(predict_all, truth_all) r_2 = eleceval.r2(predict_all, truth_all) print("After %d training step(s)," "on test data MAPE = %.4f,MAE = %.4f,MSE = %.4f,RMSE = %.4f,R2 = %.4f,Pinball loss = %.4f"\ % (epoch, mape, mae, mse, rmse, r_2, a)) if a <= self.pinball_flag: self.pinball_flag = a # 两个ndarray列合并 # y_con = np.concatenate((truth_all, predict_all), axis=1) truth_all_reshape = np.reshape(y_test[:, 0], [-1, 1]) predict_all_reshape = pred y_con = np.concatenate((truth_all_reshape, predict_all_reshape), axis=1) # 输出真实值和预测值0 y_out = pd.DataFrame(y_con) y_out.to_csv('result1h/steps=%d-pinball=%.4f.csv' % (epoch, a))
def on_epoch_begin(self, epoch, logs={}): #print(f'x_test[0:1] = {x_test[0:1]}.') #print(f'y_test[0:1] = {y_test[0:1]}.') #print(f'pred = {self.model.predict(x_test[0:1])}.') lr = K.get_value(model.optimizer.lr) print("current learning rate is {}".format(lr)) pred = model.predict({'input_layer': x_test, 'aux_input': aux_x_test}) #print('pred.shape:') #print(pred.shape) #print('y_test.shape:') #print(y_test.shape) predict_all = pred.flatten() truth_all = y_test.flatten() ''' pred_train = model.predict(x_train) predict_train = pred_train.flatten() truth_train = y_train.flatten() mape_train = eleceval.calcMAPE(predict_train,truth_train) mae_train = eleceval.calcMAE(predict_train,truth_train) mse_train = eleceval.calcMSE(predict_train,truth_train) rmse_train = eleceval.calcRMSE(predict_train,truth_train) r_2_train = eleceval.r2(predict_train,truth_train) print("After %d training step(s)," "on test data MAPE_train = %.4f,MAE_train = %.4f,MSE_train = %.4f,RMSE_train = %.4f,R2_train = %.4f"\ % (i*10, mape_train,mae_train,mse_train,rmse_train,r_2_train)) ''' mape = eleceval.calcMAPE(predict_all, truth_all) mae = eleceval.calcMAE(predict_all, truth_all) mse = eleceval.calcMSE(predict_all, truth_all) rmse = eleceval.calcRMSE(predict_all, truth_all) r_2 = eleceval.r2(predict_all, truth_all) print("After %d training step(s)," "on test data MAPE = %.4f,MAE = %.4f,MSE = %.4f,RMSE = %.4f,R2 = %.4f"\ % (epoch, mape,mae,mse,rmse,r_2)) if mape <= self.mape_flag: self.mape_flag = mape #两个ndarray列合并 #y_con = np.concatenate((truth_all, predict_all), axis=1) truth_all_reshape = np.reshape(truth_all, [-1, 1]) predict_all_reshape = np.reshape(predict_all, [-1, 1]) y_con = np.concatenate((truth_all_reshape, predict_all_reshape), axis=1) #输出真实值和预测值 y_out = pd.DataFrame(y_con, columns=["true_data", "pre_data"]) y_out.to_csv( '/media/dzf/data/data/MSFNN_train_result/0_test_causal_3datasplit_seqoutput/steps=%d-MAPE=%.4f.csv' % (epoch, mape))
def on_epoch_begin(self, epoch, logs={}): #print(f'x_test[0:1] = {x_test[0:1]}.') #print(f'y_test[0:1] = {y_test[0:1]}.') #print(f'pred = {self.model.predict(x_test[0:1])}.') lr = K.get_value(model.optimizer.lr) print("current learning rate is {}".format(lr)) pred = model.predict(x_test) predict_all = pred.flatten() truth_all = y_test.flatten() mape = eleceval.calcMAPE(predict_all, truth_all) mae = eleceval.calcMAE(predict_all, truth_all) mse = eleceval.calcMSE(predict_all, truth_all) rmse = eleceval.calcRMSE(predict_all, truth_all) r_2 = eleceval.r2(predict_all, truth_all) pinball = pinball_score(y_test, pred, 9) prediction = pred truth = y_test[:, 0] winkler40 = winkler_score(truth, prediction[:, 2], prediction[:, 6], 0.4) winkler80 = winkler_score(truth, prediction[:, 0], prediction[:, 8], 0.8) pcip40 = PCIP(truth, prediction[:, 2], prediction[:, 6], 0.4) pcip80 = PCIP(truth, prediction[:, 0], prediction[:, 8], 0.8) ace40 = pcip40 - 0.4 ace80 = pcip80 - 0.8 ecr40 = ECR(prediction[:, 2], prediction[:, 6]) / (np.max(truth) - np.min(truth)) ecr80 = ECR(prediction[:, 0], prediction[:, 8]) / (np.max(truth) - np.min(truth)) print("After %d training step(s)," "on test data MAPE = %.4f,MAE = %.4f,MSE = %.4f,RMSE = %.4f,R2 = %.4f,piball_loss = %.4f,winkler40 = %.4f,winkler80 = %.4f,pcip40 = %.4f,pcip80 = %.4f,ace40 = %.4f,ace80 = %.4f,ecr40 = %.4f,ecr80 = %.4f"\ % (epoch, mape,mae,mse,rmse,r_2,pinball,winkler40,winkler80,pcip40,pcip80,ace40,ace80,ecr40,ecr80)) if pinball < self.pinball_flag: self.pinball_flag = pinball #两个ndarray列合并 #y_con = np.concatenate((truth_all, predict_all), axis=1) truth_all_reshape = np.reshape(truth_all, [-1, 1]) predict_all_reshape = np.reshape(predict_all, [-1, 1]) y_con = np.concatenate((truth_all_reshape, predict_all_reshape), axis=1) #输出真实值和预测值 y_out = pd.DataFrame(y_con, columns=["true_data", "pre_data"]) y_out.to_csv('./result_929_3cluster/steps=%d-MAPE=%.4f,MAE = %.4f,MSE = %.4f,RMSE = %.4f,R2 = %.4f,piball_loss = %.4f,winkler40 = %.4f,winkler80 = %.4f,pcip40 = %.4f,pcip80 = %.4f,ace40 = %.4f,ace80 = %.4f,ecr40 = %.4f,ecr80 = %.4f.csv'\ % (epoch,mape,mae,mse,rmse,r_2,pinball,winkler40,winkler80,pcip40,pcip80,ace40,ace80,ecr40,ecr80))