From 50d2a3b8896f92f8216b4c881385724825109ce0 Mon Sep 17 00:00:00 2001 From: jakubknczny Date: Sat, 15 May 2021 22:30:25 +0200 Subject: [PATCH] train into eval --- lab5/eval/eval.py | 37 +++++++++++++++++++++++++++++++++++-- lab5/eval/requirements.txt | 3 ++- lab5/train/train.py | 18 ++++++------------ 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/lab5/eval/eval.py b/lab5/eval/eval.py index 4e9f330..b11782c 100644 --- a/lab5/eval/eval.py +++ b/lab5/eval/eval.py @@ -1,17 +1,50 @@ import csv import pandas as pd -from tensorflow.keras.models import load_model +import seaborn as sns +import sys +import tensorflow +from tensorflow.keras import layers +# from tensorflow.keras.models import load_model +# X_test = pd.read_csv('test.csv') +# +# Y_test = X_test.pop('stabf') +# Y_test = pd.get_dummies(Y_test) +# +# model = load_model('grid-stability-dense.h5') +X_train = pd.read_csv('train.csv') X_test = pd.read_csv('test.csv') +X_valid = pd.read_csv('valid.csv') + +Y_train = X_train.pop('stabf') +Y_train = pd.get_dummies(Y_train) Y_test = X_test.pop('stabf') Y_test = pd.get_dummies(Y_test) -model = load_model('grid-stability-dense.h5') +Y_valid = X_valid.pop('stabf') +Y_valid = pd.get_dummies(Y_valid) + +model = tensorflow.keras.Sequential([ + layers.Input(shape=(12,)), + layers.Dense(32), + layers.Dense(16), + layers.Dense(2, activation='softmax') +]) + +model.compile( + loss=tensorflow.keras.losses.BinaryCrossentropy(), + optimizer=tensorflow.keras.optimizers.Adam(lr=float(sys.argv[1])), + metrics=[tensorflow.keras.metrics.BinaryAccuracy()]) + +history = model.fit(X_train, Y_train, epochs=2, validation_data=(X_valid, Y_valid)) results = model.evaluate(X_test, Y_test, batch_size=64) with open('eval.csv', 'a', newline='') as fp: wr = csv.writer(fp, dialect='excel') wr.writerow(results) +sns.set_theme(style="darkgrid") +df = pd.read_csv('eval.csv') +sns.lineplot(x='build', y='score', data=df.iloc[1]) \ No newline at end of file diff --git a/lab5/eval/requirements.txt b/lab5/eval/requirements.txt index 33e4e92..540beef 100644 --- a/lab5/eval/requirements.txt +++ b/lab5/eval/requirements.txt @@ -1,4 +1,5 @@ numpy~=1.19.2 pandas tensorflow -keras==2.4.3 +keras +seaborn diff --git a/lab5/train/train.py b/lab5/train/train.py index 099c934..0f3c519 100644 --- a/lab5/train/train.py +++ b/lab5/train/train.py @@ -16,18 +16,12 @@ Y_test = pd.get_dummies(Y_test) Y_valid = X_valid.pop('stabf') Y_valid = pd.get_dummies(Y_valid) -# model = tensorflow.keras.Sequential([ -# layers.Input(shape=(12,)), -# layers.Dense(32), -# layers.Dense(16), -# layers.Dense(2, activation='softmax') -# ]) - -model = tensorflow.keras.Sequential() -model.add(layers.Input(shape=(12,))) -model.add(layers.Dense(32)) -model.add(layers.Dense(16)) -model.add(layers.Dense(2, activation='softmax')) +model = tensorflow.keras.Sequential([ + layers.Input(shape=(12,)), + layers.Dense(32), + layers.Dense(16), + layers.Dense(2, activation='softmax') +]) model.compile( loss=tensorflow.keras.losses.BinaryCrossentropy(),