|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
import math |
|
from metrics import MAE, MAPE, RMSE |
|
import csv |
|
|
|
|
|
|
|
def show_pred(all_y_true, all_predict_values, horizon): |
|
time_steps = horizon |
|
|
|
|
|
header = ['test_y', 'predicted_values'] |
|
ele_values = np.concatenate((all_y_true[:, 0, :1], all_predict_values[:, 0, :1]), axis=1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_and_concatenate(arr): |
|
result = [] |
|
for feature in range(arr.shape[2]): |
|
|
|
extracted = arr[::horizon, :, feature].reshape(-1) |
|
result.append(extracted) |
|
return result |
|
|
|
|
|
mae1 = MAE(all_y_true[:, :, :1], all_predict_values[:, :, :1]) |
|
mape1 = MAPE(all_y_true[:, :, :1], all_predict_values[:, :, :1]) |
|
rmase1 = RMSE(all_y_true[:, :, :1], all_predict_values[:, :, :1]) |
|
predict = all_predict_values[:, :, :1] |
|
Ytest = all_y_true[:, :, :1] |
|
sigma_p = (predict).std(axis=0) |
|
sigma_g = (Ytest).std(axis=0) |
|
mean_p = predict.mean(axis=0) |
|
mean_g = Ytest.mean(axis=0) |
|
index = (sigma_g != 0) |
|
correlation = ((predict - mean_p) * (Ytest - mean_g)).mean(axis=0) / (sigma_p * sigma_g) |
|
correlation1 = (correlation[index]).mean() |
|
print("============整个测试集电负荷===================") |
|
print("MAE = " + str(mae1)) |
|
print("MAPE = " + str(mape1)) |
|
print("RMSE = " + str(rmase1)) |
|
print("acc = " + str(correlation1)) |
|
|
|
print("============整个测试集cooling==================") |
|
mae2 = MAE(all_y_true[:, :, 1:2], all_predict_values[:, :, 1:2]) |
|
mape2 = MAPE(all_y_true[:, :, 1:2], all_predict_values[:, :, 1:2]) |
|
rmase2 = RMSE(all_y_true[:, :, 1:2], all_predict_values[:, :, 1:2]) |
|
predict = all_predict_values[:, :, 1:2] |
|
Ytest = all_y_true[:, :, 1:2] |
|
sigma_p = (predict).std(axis=0) |
|
sigma_g = (Ytest).std(axis=0) |
|
mean_p = predict.mean(axis=0) |
|
mean_g = Ytest.mean(axis=0) |
|
index = (sigma_g != 0) |
|
correlation = ((predict - mean_p) * (Ytest - mean_g)).mean(axis=0) / (sigma_p * sigma_g) |
|
correlation2 = (correlation[index]).mean() |
|
print("MAE = " + str(mae2)) |
|
print("MAPE = " + str(mape2)) |
|
print("RMSE = " + str(rmase2)) |
|
print("acc = " + str(correlation2)) |
|
|
|
print("==============整个测试集heating=================") |
|
mae3 = MAE(all_y_true[:, :, 2:3], all_predict_values[:, :, 2:3]) |
|
mape3 = MAPE(all_y_true[:, :, 2:3], all_predict_values[:, :, 2:3]) |
|
rmase3 = RMSE(all_y_true[:, :, 2:3], all_predict_values[:, :, 2:3]) |
|
|
|
predict = all_predict_values[:, :, 2:3] |
|
Ytest = all_y_true[:, :, 2:3] |
|
sigma_p = (predict).std(axis=0) |
|
sigma_g = (Ytest).std(axis=0) |
|
mean_p = predict.mean(axis=0) |
|
mean_g = Ytest.mean(axis=0) |
|
index = (sigma_g != 0) |
|
correlation = ((predict - mean_p) * (Ytest - mean_g)).mean(axis=0) / (sigma_p * sigma_g) |
|
correlation3 = (correlation[index]).mean() |
|
print("MAE = " + str(mae3)) |
|
print("MAPE = " + str(mape3)) |
|
print("RMSE = " + str(rmase3)) |
|
print("acc = " + str(correlation3)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y_true_extracted = extract_and_concatenate(all_y_true) |
|
predict_values_extracted = extract_and_concatenate(all_predict_values) |
|
|
|
|
|
|
|
|
|
node_id = 0 |
|
|
|
plt.figure(figsize=(20, 10)) |
|
plt.title("electricity") |
|
plt.xlabel("time/one_hour") |
|
plt.ylabel("electricity") |
|
|
|
|
|
plt.plot(y_true_extracted[node_id], linewidth=1.0, label='true') |
|
plt.plot(predict_values_extracted[node_id], linewidth=1.0, label='pred') |
|
plt.legend() |
|
plt.savefig("./assets/the first month pred electricity.png") |
|
|
|
|
|
node_id = 1 |
|
|
|
plt.figure(figsize=(20, 10)) |
|
plt.title("cooling") |
|
plt.xlabel("time/one_hour") |
|
plt.ylabel("electricity") |
|
|
|
|
|
plt.plot(y_true_extracted[node_id], linewidth=1.0, label='true') |
|
plt.plot(predict_values_extracted[node_id], linewidth=1.0, label='pred') |
|
plt.legend() |
|
plt.savefig("./assets/the first month pred cooling.png") |
|
|
|
|
|
node_id = 2 |
|
|
|
plt.figure(figsize=(20, 10)) |
|
plt.title("heating") |
|
plt.xlabel("time/one_hour") |
|
plt.ylabel("heating") |
|
|
|
|
|
plt.plot(y_true_extracted[node_id], linewidth=1.0, label='true') |
|
plt.plot(predict_values_extracted[node_id], linewidth=1.0, label='pred') |
|
plt.legend() |
|
plt.savefig("./assets/the first month pred heating.png") |
|
|
|
|
|
mae = MAE(all_y_true, all_predict_values) |
|
rmse = RMSE(all_y_true, all_predict_values) |
|
mape = MAPE(all_y_true, all_predict_values) |
|
|
|
print("ST-GCN基于原始值的精度指标 mae: {:02.4f}, rmse: {:02.4f}, mape: {:02.4f}".format(mae, rmse, mape)) |
|
|
|
|
|
y_true_concatenated = np.concatenate(y_true_extracted) |
|
predict_values_concatenated = np.concatenate(predict_values_extracted) |
|
mae2 = MAE(y_true_concatenated, predict_values_concatenated) |
|
rmse2 = RMSE(y_true_concatenated, predict_values_concatenated) |
|
mape2 = MAPE(y_true_concatenated, predict_values_concatenated) |
|
|
|
print("ST-GCN拼接后的精度指标 mae: {:02.4f}, rmse: {:02.4f}, mape: {:02.4f}".format(mae2, rmse2, mape2)) |
|
|
|
|
|
all_y_true_loaded_np = np.load('./result/all_y_true.npy') |
|
all_predict_value_loaded_np = np.load('./result/all_predict_value.npy') |
|
show_pred(all_y_true_loaded_np, all_predict_value_loaded_np, 24) |
|
|