Added 24 hour prediction
This commit is contained in:
parent
fd623c32de
commit
0e228772dc
3 changed files with 49 additions and 4 deletions
|
@ -68,6 +68,22 @@ def predict(nn, X_pred):
|
|||
return predictions
|
||||
|
||||
|
||||
def predict24h(nn, X_pred):
|
||||
predictions = []
|
||||
|
||||
input = {'dc': X_pred['dc'].tolist()}
|
||||
|
||||
for i in range(24):
|
||||
pred = nn.predict1h(pandas.DataFrame.from_dict(input))
|
||||
predictions.extend(list([p['predictions'][0] for p in pred]))
|
||||
# Remove first value and append predicted value
|
||||
del input['dc'][0]
|
||||
input['dc'].append(predictions[-1])
|
||||
print(input)
|
||||
|
||||
return predictions
|
||||
|
||||
|
||||
def eval_prediction(prediction, result):
|
||||
print("The Explained Variance: %.2f" % explained_variance_score(
|
||||
result, prediction))
|
||||
|
|
|
@ -6,7 +6,6 @@ import tensorflow as tf
|
|||
def pywatts_input_fn(X, y=None, num_epochs=None, shuffle=True, batch_size=1):
|
||||
# Create dictionary for features in hour 0 ... 335
|
||||
features = {str(idx): [] for idx in range(336)}
|
||||
#dc_values = X['dc'].tolist()
|
||||
dc_values = X['dc']
|
||||
|
||||
# Iterate the empty dictionary always adding the idx-th element from the dc_values list
|
||||
|
@ -15,7 +14,6 @@ def pywatts_input_fn(X, y=None, num_epochs=None, shuffle=True, batch_size=1):
|
|||
|
||||
labels = None
|
||||
if y is not None:
|
||||
#labels = y['dc'].values
|
||||
labels = y['dc']
|
||||
|
||||
if labels is None:
|
||||
|
@ -24,9 +22,11 @@ def pywatts_input_fn(X, y=None, num_epochs=None, shuffle=True, batch_size=1):
|
|||
dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels))
|
||||
|
||||
if shuffle:
|
||||
dataset.shuffle(len(features['0']))
|
||||
dataset.shuffle(len(features['0']*len(features)*4))
|
||||
|
||||
return dataset.batch(batch_size)
|
||||
return dataset.repeat().batch(batch_size)
|
||||
else:
|
||||
return dataset.batch(batch_size)
|
||||
|
||||
|
||||
class Net:
|
||||
|
|
29
pywatts/test_predict24.py
Normal file
29
pywatts/test_predict24.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import tensorflow as tf
|
||||
import pywatts.db
|
||||
from pywatts.main import *
|
||||
import matplotlib.pyplot as pp
|
||||
|
||||
|
||||
PREDICT_QUERY = "query-sample_24hour.json"
|
||||
PREDICT_RESULT = PREDICT_QUERY.replace("query", "result")
|
||||
QUERY_ID = 0
|
||||
|
||||
|
||||
pred_query = input_query("../sample_data/" + PREDICT_QUERY, QUERY_ID)
|
||||
pred_result = input_result("../sample_data/" + PREDICT_RESULT, QUERY_ID)
|
||||
|
||||
|
||||
# Define feature columns and initialize Regressor
|
||||
feature_col = [tf.feature_column.numeric_column(str(idx)) for idx in range(336)]
|
||||
n = pywatts.neural.Net(feature_cols=feature_col)
|
||||
|
||||
prediction = predict24h(n, pred_query)
|
||||
|
||||
print(prediction)
|
||||
print(pred_result)
|
||||
|
||||
pp.plot(pred_result, 'black')
|
||||
pp.plot(prediction, 'red')
|
||||
pp.show()
|
||||
|
||||
#pywatts.main.eval_prediction(prediction, pred_result)
|
Loading…
Reference in a new issue