From 9aa2b7d4ad7201f5fc2ed519e55a1c31b1147971 Mon Sep 17 00:00:00 2001 From: Wojciech Jarmosz Date: Sat, 15 May 2021 03:50:19 +0200 Subject: [PATCH] Fixes for lab5, lab6 --- Jenkinsfile | 2 +- linear_regression.py | 27 +++++++++++---------------- training.py | 29 +++++++++++++---------------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index eb34a15..16ab74f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,7 +18,7 @@ stages { // sh "chmod 777 ./data_download.sh" // sh "./data_download.sh" // Zapisanie artefaktów - archiveArtifacts "results.txt" + archiveArtifacts "results_lab5.txt" archiveArtifacts "MoviesOnStreamingPlatforms_updated.dev" archiveArtifacts "MoviesOnStreamingPlatforms_updated.test" archiveArtifacts "MoviesOnStreamingPlatforms_updated.train" diff --git a/linear_regression.py b/linear_regression.py index 15335e5..75e019c 100644 --- a/linear_regression.py +++ b/linear_regression.py @@ -23,24 +23,19 @@ test_Y = tf.convert_to_tensor(test_data[["IMDb"]]) normalizer = preprocessing.Normalization(input_shape=[3,]) normalizer.adapt(train_X) -if os.path.isdir('linear_regression'): - model = keras.models.load_model('linear_regression') -else: - model = keras.Sequential([ - keras.Input(shape=(len(columns_to_use),)), - normalizer, - layers.Dense(30, activation='relu'), - layers.Dense(10, activation='relu'), - layers.Dense(25, activation='relu'), - layers.Dense(1) - ]) +model = keras.Sequential([ + keras.Input(shape=(len(columns_to_use),)), + normalizer, + layers.Dense(30, activation='relu'), + layers.Dense(10, activation='relu'), + layers.Dense(25, activation='relu'), + layers.Dense(1) +]) - model.compile(loss='mean_absolute_error', - optimizer=tf.keras.optimizers.Adam(0.001)) +model.compile(loss='mean_absolute_error', + optimizer=tf.keras.optimizers.Adam(0.001)) - model.fit(train_X, train_Y, verbose=0, epochs=100) - - model.save('linear_regression') +model.fit(train_X, train_Y, verbose=0, epochs=100) # Predykcja na danych testowych results = model.predict(test_X) diff --git a/training.py b/training.py index f3b3e23..68e91fe 100644 --- a/training.py +++ b/training.py @@ -27,22 +27,19 @@ train_Y = tf.convert_to_tensor(train_data[["IMDb"]]) normalizer = preprocessing.Normalization(input_shape=[3,]) normalizer.adapt(train_X) -if os.path.isdir('linear_regression'): - model = keras.models.load_model('linear_regression') -else: - model = keras.Sequential([ - keras.Input(shape=(len(columns_to_use),)), - normalizer, - layers.Dense(30, activation='relu'), - layers.Dense(10, activation='relu'), - layers.Dense(25, activation='relu'), - layers.Dense(1) - ]) +model = keras.Sequential([ + keras.Input(shape=(len(columns_to_use),)), + normalizer, + layers.Dense(30, activation='relu'), + layers.Dense(10, activation='relu'), + layers.Dense(25, activation='relu'), + layers.Dense(1) +]) - model.compile(loss='mean_absolute_error', - optimizer=tf.keras.optimizers.Adam(0.001), - metrics=[tf.keras.metrics.RootMeanSquaredError()]) +model.compile(loss='mean_absolute_error', + optimizer=tf.keras.optimizers.Adam(0.001), + metrics=[tf.keras.metrics.RootMeanSquaredError()]) - model.fit(train_X, train_Y, verbose=verbose, epochs=epochs) +model.fit(train_X, train_Y, verbose=verbose, epochs=epochs) - model.save('linear_regression.h5') \ No newline at end of file +model.save('linear_regression.h5') \ No newline at end of file