From 630aba321709bb4d9d29c413a66e20f570a4f84a Mon Sep 17 00:00:00 2001 From: Karolina Oparczyk Date: Mon, 17 May 2021 22:04:40 +0200 Subject: [PATCH] evaluation branch --- JenkinsFIleEval | 0 evaluate_network.py | 38 ++++++++++++++++++++++++++++++++++++++ neural_network.py | 33 --------------------------------- 3 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 JenkinsFIleEval create mode 100644 evaluate_network.py diff --git a/JenkinsFIleEval b/JenkinsFIleEval new file mode 100644 index 0000000..e69de29 diff --git a/evaluate_network.py b/evaluate_network.py new file mode 100644 index 0000000..52421ab --- /dev/null +++ b/evaluate_network.py @@ -0,0 +1,38 @@ +import pandas as pd +import numpy as np +from sklearn.metrics import mean_squared_error +from tensorflow import keras + +model = keras.models.load_model('model') +data = pd.read_csv("data_dev", sep=',', error_bad_lines=False, + skip_blank_lines=True, nrows=527, names=["video_id", "last_trending_date", + "publish_date", "publish_hour", "category_id", + "channel_title", "views", "likes", "dislikes", + "comment_count"]).dropna() +X_test = data.loc[:,data.columns == "views"].astype(int) +y_test = data.loc[:,data.columns == "likes"].astype(int) + +min_val_sub = np.min(X_test) +max_val_sub = np.max(X_test) +X_test = (X_test - min_val_sub) / (max_val_sub - min_val_sub) +print(min_val_sub) +print(max_val_sub) + +min_val_like = np.min(y_test) +max_val_like = np.max(y_test) +print(min_val_like) +print(max_val_like) + +prediction = model.predict(X_test) + +prediction_denormalized = [] +for pred in prediction: + denorm = pred[0] * (max_val_like[0] - min_val_like[0]) + min_val_like[0] + prediction_denormalized.append(denorm) + +f = open("predictions.txt", "w") +for (pred, test) in zip(prediction_denormalized, y_test.values): + f.write("predicted: %s expected: %s\n" % (str(pred), str(test[0]))) + +error = mean_squared_error(y_test, prediction_denormalized) +print(error) diff --git a/neural_network.py b/neural_network.py index d3ffe28..aa6f4a4 100644 --- a/neural_network.py +++ b/neural_network.py @@ -42,37 +42,4 @@ model.compile(loss='mean_absolute_error', optimizer="Adam", metrics=['mean_absol model.fit(X, y, epochs=int(sys.argv[1]), validation_split = 0.3) -data = pd.read_csv("data_dev", sep=',', error_bad_lines=False, - skip_blank_lines=True, nrows=527, names=["video_id", "last_trending_date", - "publish_date", "publish_hour", "category_id", - "channel_title", "views", "likes", "dislikes", - "comment_count"]).dropna() -X_test = data.loc[:,data.columns == "views"].astype(int) -y_test = data.loc[:,data.columns == "likes"].astype(int) - -min_val_sub = np.min(X_test) -max_val_sub = np.max(X_test) -X_test = (X_test - min_val_sub) / (max_val_sub - min_val_sub) -print(min_val_sub) -print(max_val_sub) - -min_val_like = np.min(y_test) -max_val_like = np.max(y_test) -print(min_val_like) -print(max_val_like) - -prediction = model.predict(X_test) - -prediction_denormalized = [] -for pred in prediction: - denorm = pred[0] * (max_val_like[0] - min_val_like[0]) + min_val_like[0] - prediction_denormalized.append(denorm) - -f = open("predictions.txt", "w") -for (pred, test) in zip(prediction_denormalized, y_test.values): - f.write("predicted: %s expected: %s\n" % (str(pred), str(test[0]))) - -error = mean_squared_error(y_test, prediction_denormalized) -print(error) - model.save('model') \ No newline at end of file