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) print('NRMSE is ', nrmse) fig = plt.figure(figsize=(12, 9), dpi=100) plt.subplot(2, 1, 1) plt.plot(ca_y_test, label="$lowpass_real$", c='green') plt.plot(ca_pred, label="$lowpass_prediction$", c='red') plt.legend(['lowpass_real', 'lowpass_prediction'], loc='upper right') plt.title('lowpass coefficient prediction result', fontsize=16)
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 = [] for j in range(len(preds)): print(j) x, = plt.plot(preds[j]+shifted_value, color=colors[j]) legendVars.append(x)
plt.show() ''' # show result of predictions # pr = pred2.predicted_mean['2016-07-10 19:00:00':'2016-07-31 23:00:00']+shifted_value # ax = (data['2016-07-10 19:00:00':'2016-07-31 23:00:00']+shifted_value).plot(figsize=(20, 16)) pr = pred2.predicted_mean['2016-12-01 22:00:00':'2017-05-16 21:00:00'] ax = (data['2016-12-01 22:00:00':'2017-05-16 21:00:00']).plot(figsize=(20, 16)) # plot the results fig = plt.figure() plt.plot(ax, label="$true$", c='green') plt.plot(pr, label="$predict$", c='red') plt.xlabel('Hour') plt.ylabel('Electricity load (*1e3)') plt.legend() plt.show() fig.savefig('../result/sarimax.jpg', bbox_inches='tight') # quantify the accuracy of the prediction prediction = pred2.predicted_mean['2016-12-01 22:00:00':'2017-05-16 21:00:00'].values # flatten nested list truth = list(itertools.chain.from_iterable(test_data.values)) # evaluation mape = np.mean(np.abs((truth - prediction) / truth)) print('mape is {:.5f}'.format(mape)) mae = statistics.mae(truth,prediction) print('MAE is ', mae) mse = statistics.meanSquareError(truth,prediction) print('MSE is ', mse) rmse = statistics.Rmse(mse) print('RMSE is ', rmse) nrmse = statistics.normRmse(truth,prediction) print('NRMSE is ', nrmse)