diff --git a/pywatts/main.py b/pywatts/main.py index 414f87d..39950f0 100644 --- a/pywatts/main.py +++ b/pywatts/main.py @@ -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)) diff --git a/pywatts/neural.py b/pywatts/neural.py index bbe0b93..4180366 100644 --- a/pywatts/neural.py +++ b/pywatts/neural.py @@ -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: diff --git a/pywatts/test_predict24.py b/pywatts/test_predict24.py new file mode 100644 index 0000000..af5ead7 --- /dev/null +++ b/pywatts/test_predict24.py @@ -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)