From fb30c94427fb2117d2c926f350ff83256c0d87e9 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 29 May 2018 15:46:35 +0200 Subject: [PATCH] make members private and add feature_cols --- pywatts/__init__.py | 1 - pywatts/neural.py | 20 +++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pywatts/__init__.py b/pywatts/__init__.py index a180f42..07cf010 100644 --- a/pywatts/__init__.py +++ b/pywatts/__init__.py @@ -1,3 +1,2 @@ from pywatts import db from pywatts import fetchdata -from pywatts import neural diff --git a/pywatts/neural.py b/pywatts/neural.py index 18ad9de..2c09e79 100644 --- a/pywatts/neural.py +++ b/pywatts/neural.py @@ -2,13 +2,14 @@ import tensorflow as tf class Net: - regressor = None + __regressor = None + __feature_cols = [tf.feature_column.numeric_column(col) for col in ['dc', 'temp', 'wind']] - def __init__(self, feature_cols): - self.regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols, - hidden_units=[50, 50], - model_dir='tf_pywatts_model') + def __init__(self, feature_cols=__feature_cols): + self.__regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols, + hidden_units=[50, 50], + model_dir='tf_pywatts_model') def pywatts_input_fn(X, y=None, num_epochs=None, shuffle=True, batch_size=400): return tf.estimator.inputs.pandas_input_fn(x=X, @@ -18,14 +19,11 @@ class Net: batch_size=batch_size) def train(self, training_data, steps): - self.regressor.train(input_fn=self.pywatts_input_fn(training_data, num_epochs=None, shuffle=True), steps=steps) + self.__regressor.train(input_fn=self.pywatts_input_fn(training_data, num_epochs=None, shuffle=True), steps=steps) def evaluate(self, eval_data): - self.regressor.evaluate(input_fn=self.pywatts_input_fn(eval_data, num_epochs=1, shuffle=False), steps=1) + self.__regressor.evaluate(input_fn=self.pywatts_input_fn(eval_data, num_epochs=1, shuffle=False), steps=1) def predict1h(self, df): df = df.drop(['month', 'day', 'hour']) - predictions = self.regressor.predict(input_fn=self.pywatts_input_fn(df, num_epochs=1, shuffle=False)) - - - + return self.__regressor.predict(input_fn=self.pywatts_input_fn(df, num_epochs=1, shuffle=False))