Make Training Great Again!

This commit is contained in:
Paul Schaub 2018-06-11 13:47:02 +02:00
parent e5ef0cd1ee
commit c3c782bf02
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 18 additions and 4 deletions

View file

@ -1,3 +1,4 @@
from pywatts import db from pywatts import db
from pywatts import fetchdata from pywatts import fetchdata
from pywatts import neural from pywatts import neural
from pywatts import main

13
pywatts/main.py Normal file
View file

@ -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)

View file

@ -1,5 +1,6 @@
import tensorflow as tf import tensorflow as tf
def pywatts_input_fn(X, y=None, num_epochs=None, shuffle=True, batch_size=400): def pywatts_input_fn(X, y=None, num_epochs=None, shuffle=True, batch_size=400):
return tf.estimator.inputs.pandas_input_fn(x=X, return tf.estimator.inputs.pandas_input_fn(x=X,
y=y, y=y,
@ -12,14 +13,13 @@ class Net:
__regressor = None __regressor = None
__feature_cols = [tf.feature_column.numeric_column(col) for col in ['dc', 'temp', 'wind']] __feature_cols = [tf.feature_column.numeric_column(col) for col in ['dc', 'temp', 'wind']]
def __init__(self, feature_cols=__feature_cols): def __init__(self, feature_cols=__feature_cols):
self.__regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols, self.__regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols,
hidden_units=[50, 50], hidden_units=[50, 50],
model_dir='tf_pywatts_model') model_dir='tf_pywatts_model')
def train(self, training_data, steps): def train(self, training_data, training_results, steps):
self.__regressor.train(input_fn=pywatts_input_fn(training_data, num_epochs=None, shuffle=True), steps=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): 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)