Beispiel #1
0
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 = []
for j in range(len(preds)):
    print(j)
Beispiel #2
0
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)
                                    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)
print('NRMSE is ', nrmse)

fig = plt.figure(figsize=(12, 9), dpi=100)
plt.subplot(2, 1, 1)
Beispiel #4
0
 # 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)