From f2c10e764718109339d04bf2dbc92ca37551ca2e Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 27 May 2021 16:38:23 +0200 Subject: [PATCH] evaluation --- evaluation/Jenkinsfile | 34 ++++++++++++++++++++++++ evaluation/eval.py | 59 ++++++++++++++++++++++++++++++++++++++++++ evaluation/plot.py | 14 ++++++++++ 3 files changed, 107 insertions(+) create mode 100644 evaluation/Jenkinsfile create mode 100644 evaluation/eval.py create mode 100644 evaluation/plot.py diff --git a/evaluation/Jenkinsfile b/evaluation/Jenkinsfile new file mode 100644 index 0000000..29cd159 --- /dev/null +++ b/evaluation/Jenkinsfile @@ -0,0 +1,34 @@ +pipeline { + agent { + dockerfile true + } + stages { + stage('Copy Archive') { + steps { + script { + step ([$class: 'CopyArtifact', + projectName: 's434700-training', + filter: 'model.pt', + target: 'model']) + } + } + } + stage('checkout: Check out from version control') { + steps { + git 'https://git.wmi.amu.edu.pl/s434700/ium_s434700.git' + } + } + stage('evaluation') { + steps { + sh 'python ./evaluation/eval.py' + sh 'python ./evaluation/plot.py' + } + } + stage('archiveArtifacts') { + steps { + archiveArtifacts 'model_results.csv' + archiveArtifacts 'model_results.png' + } + } + } +} diff --git a/evaluation/eval.py b/evaluation/eval.py new file mode 100644 index 0000000..7ca9976 --- /dev/null +++ b/evaluation/eval.py @@ -0,0 +1,59 @@ +import torch +import torch.nn as nn +import numpy as np +import pandas as pd +import seaborn as sns +import torch +import datetime +from torch.autograd import Variable +import csv + +INPUT_DIM = 1 +OUTPUT_DIM = 1 +LEARNING_RATE = 0.01 +EPOCHS = 100 + + +dataset = pd.read_csv('train_set.csv') + +# create dummy data for training +x_values = [datetime.datetime.strptime( + item, "%Y-%m-%d").month for item in dataset['date'].values] +x_train = np.array(x_values, dtype=np.float32) +x_train = x_train.reshape(-1, 1) + +y_values = [min(dataset['result_1'].values[i]/dataset['result_2'].values[i], dataset['result_2'].values[i] / + dataset['result_1'].values[i]) for i in range(len(dataset['result_1'].values))] +y_train = np.array(y_values, dtype=np.float32) +y_train = y_train.reshape(-1, 1) + + +class LinearRegression(torch.nn.Module): + def __init__(self, inputSize, outputSize): + super(LinearRegression, self).__init__() + self.linear = torch.nn.Linear(inputSize, outputSize) + + def forward(self, x): + out = self.linear(x) + return out + + +model = LinearRegression(INPUT_DIM, OUTPUT_DIM) + +model.load_state_dict(torch.load("model/model.pt"), strict=False) + + +# testing data + +with torch.no_grad(): # we don't need gradients in the testing phase + predicted = model(Variable(torch.from_numpy(x_train))).data.numpy() + + +with open('model_results.csv', mode='w') as filee: + writer = csv.writer(filee, delimiter=',', quotechar='"', + quoting=csv.QUOTE_MINIMAL) + + writer.writerow(['x', 'y', 'predicted_y']) + + for i in range(len(x_train)): + writer.writerow([x_train[i][0], y_train[i][0], predicted[i][0]]) diff --git a/evaluation/plot.py b/evaluation/plot.py new file mode 100644 index 0000000..5741b5f --- /dev/null +++ b/evaluation/plot.py @@ -0,0 +1,14 @@ +import matplotlib.pyplot as plt +import pandas as pd + +results = pd.read_csv('model_results.csv') + +x_train = results['x'] +y_train = results['y'] +predicted = results['predicted_y'] + +plt.clf() +plt.plot(x_train, y_train, 'go', label='True data', alpha=0.5) +plt.plot(x_train, predicted, '--', label='Predictions', alpha=0.5) +plt.legend(loc='best') +plt.savefig('model_results.png')