From c3c782bf02ea0d6fce86ed56800aae94abaddd1b Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 11 Jun 2018 13:47:02 +0200 Subject: [PATCH] Make Training Great Again! --- pywatts/__init__.py | 3 ++- pywatts/main.py | 13 +++++++++++++ pywatts/neural.py | 6 +++--- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 pywatts/main.py diff --git a/pywatts/__init__.py b/pywatts/__init__.py index 1f4d617..c71aa1f 100644 --- a/pywatts/__init__.py +++ b/pywatts/__init__.py @@ -1,3 +1,4 @@ from pywatts import db from pywatts import fetchdata -from pywatts import neural \ No newline at end of file +from pywatts import neural +from pywatts import main \ No newline at end of file diff --git a/pywatts/main.py b/pywatts/main.py new file mode 100644 index 0000000..3c48e4b --- /dev/null +++ b/pywatts/main.py @@ -0,0 +1,13 @@ +import tensorflow as tf +import pywatts.neural + +from sklearn.model_selection import train_test_split + +df = pywatts.db.rows_to_df(list(range(1, 50))) +X = df[[col for col in df.columns if col != 'dc']] +y = df['dc'] + +X_train, X_tmp, y_train, y_tmp = train_test_split(X, y, test_size=0.2, random_state=23) + +feature_cols = [tf.feature_column.numeric_column(col) for col in X.columns] +n = pywatts.neural.Net(feature_cols=feature_cols) \ No newline at end of file diff --git a/pywatts/neural.py b/pywatts/neural.py index 10b75bc..49b5efc 100644 --- a/pywatts/neural.py +++ b/pywatts/neural.py @@ -1,5 +1,6 @@ import tensorflow as tf + def pywatts_input_fn(X, y=None, num_epochs=None, shuffle=True, batch_size=400): return tf.estimator.inputs.pandas_input_fn(x=X, y=y, @@ -12,14 +13,13 @@ class Net: __regressor = None __feature_cols = [tf.feature_column.numeric_column(col) for col in ['dc', 'temp', 'wind']] - 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 train(self, training_data, steps): - self.__regressor.train(input_fn=pywatts_input_fn(training_data, num_epochs=None, shuffle=True), steps=steps) + def train(self, training_data, training_results, steps): + self.__regressor.train(input_fn=pywatts_input_fn(training_data, y=training_results, 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)