pywatts/pywatts/test_train.py

50 lines
1.0 KiB
Python
Raw Normal View History

2018-06-23 15:00:16 +02:00
import tensorflow as tf
2018-09-09 17:25:43 +02:00
2018-06-23 15:00:16 +02:00
import pywatts.db
2018-08-13 14:31:39 +02:00
from pywatts.routines import *
2018-06-23 15:00:16 +02:00
2018-06-23 15:40:45 +02:00
NUM_STATIONS_FROM_DB = 75
2018-08-06 13:28:27 +02:00
NUM_TRAIN_STATIONS = 400
NUM_EVAL_STATIONS = 40
2018-06-23 15:00:16 +02:00
TRAIN = True
PLOT = True
2018-08-06 13:28:27 +02:00
TRAIN_STEPS = 50
2018-06-23 15:00:16 +02:00
df = pywatts.db.rows_to_df(list(range(1, NUM_STATIONS_FROM_DB)))
X = df
y = df['dc']
#X_train, X_tmp, y_train, y_tmp = train_test_split(X, y, test_size=0.2, random_state=34)
#X_test, X_val, y_test, y_val = train_test_split(X_tmp, y_tmp, test_size=0.5, random_state=23)
# 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)
# Training data
(X_train, y_train) = train_split(df, NUM_TRAIN_STATIONS)
# Evaluation data
(X_val, y_val) = train_split(df, NUM_EVAL_STATIONS)
train_eval = {}
if TRAIN:
# Train the model with the steps given
train_eval = train(n, X_train, y_train, X_val, y_val, TRAIN_STEPS)
if PLOT:
# Plot training success rate (with 'average loss')
2018-08-13 14:31:39 +02:00
pywatts.routines.plot_training(train_eval)
2018-06-23 15:00:16 +02:00
exit()