# get the predicted values ca_pred = ca_model.predict(ca_X_test)[:, 0] print('Lowpass coefficient estimation finish.') mu, sigma_2, cd_pred = generateData(cd[0:train_row], outputnum=len(cd) - 24 - train_row) # cd_pred = cd_model.predict(cd_X_test)[:,0] print('Highpass coefficient estimation finish.') #print(np.shape(ca_pred),np.shape(cd_pred)) predicted_values = idwt((ca_pred + shifted_value_ca) * 10, cd_pred) #predicted_values = idwt(ca_pred+ca_shifted_value, cd_pred+cd_shifted_value) print('IDWT finish.') # mape = statistics.mape([y_test_true[i]*1000 for i in range(0,len(y_test_true))],(predicted_values)*1000 print(len(y_test_true), len(predicted_values)) mape = statistics.mape([(y_test_true[i] + shifted_value) * 1000 for i in range(0, len(y_test_true))], (predicted_values + shifted_value) * 1000) print('MAPE is ', mape) mae = statistics.mae([(y_test_true[i] + shifted_value) * 1000 for i in range(0, len(y_test_true))], (predicted_values + shifted_value) * 1000) print('MAE is ', mae) mse = statistics.meanSquareError([(y_test_true[i] + shifted_value) * 1000 for i in range(0, len(y_test_true))], (predicted_values + shifted_value) * 1000) print('MSE is ', mse) rmse = math.sqrt(mse) print('RMSE is ', rmse) nrmse = statistics.normRmse([(y_test_true[i] + shifted_value) * 1000 for i in range(0, len(y_test_true))], (predicted_values + shifted_value) * 1000)
names = [] names.append('true') for x in range(len(dimensions)): s = "d=" + str(dimensions[x]) + ",h=" + str(neurons[x]) names.append(s) preds = [] preds.append(y_test) for x in range(len(dimensions)): i = 0 # Perform dimensionality reduction on the feature vectors pca = PCA(n_components=dimensions[x]) pca.fit(X_train) xTrainRed = pca.transform(X_train) xTestRed = pca.transform(X_test) predicted_values = fit_predict(xTrainRed, y_train, xTestRed, 40, neurons[x]) mape = statistics.mape((y_test + shifted_value) * 1000, (predicted_values + shifted_value) * 1000) print('MAPE is ', mape) mae = statistics.mae((y_test + shifted_value) * 1000, (predicted_values + shifted_value) * 1000) print('MAE is ', mae) mse = statistics.meanSquareError((y_test + shifted_value) * 1000, (predicted_values + shifted_value) * 1000) print('MSE is ', mse) rmse = math.sqrt(mse) print('RMSE is ', rmse) nrmse = statistics.normRmse((y_test + shifted_value) * 1000, (predicted_values + shifted_value) * 1000) print('NRMSE is ', nrmse) print (i+1) preds.append(predicted_values) # show fig = plt.figure() colors = ["g","r","b","c","m","y","k","w"] legendVars = []
# save model model.save('../model/seq2seq_code.h5') model = load_model('../model/seq2seq_code.h5') # evaluate on some new patterns result = model.predict(X_test, batch_size=50, verbose=0) # calculate error,evaluate the result predicted = one_hot_decode(result, series_min, series_max, n_unique) # plot the results fig = plt.figure() plt.plot(test[:, n_in:] + shifted_value, label="$true$", c='green') plt.plot(predicted + shifted_value, label="$predict$", c='red') plt.xlabel('Hour') plt.ylabel('Electricity load') plt.legend() plt.show() fig.savefig('../result/seq2seq_code_result.jpg', bbox_inches='tight') # evaluation mape = statistics.mape(test[:, n_in:] + shifted_value, predicted + shifted_value) print('MAPE is ', mape) nrmse = statistics.normRmse(test[:, n_in:] + shifted_value, predicted + shifted_value) print('NRMSE is ', nrmse) mae = statistics.mae(test[:, n_in:] + shifted_value, predicted + shifted_value) print('MAE is ', mae) mse = statistics.mse(test[:, n_in:] + shifted_value, predicted + shifted_value) print('MSE is ', mse) rmse = sqrt(mse) print('RMSE is ', rmse)