diff --git a/JenkinsfileEval b/JenkinsfileEval new file mode 100644 index 0000000..55fde7d --- /dev/null +++ b/JenkinsfileEval @@ -0,0 +1,20 @@ +node { + stage('Preparation') { + checkout scm + copyArtifacts projectName: 's470618-metrics', filter: 'metrics.txt', fingerprintArtifacts: true, selector: lastSuccessful(), optional: true, target: './train-eval' + copyArtifacts projectName: 's470618-training', filter: '*.pt', fingerprintArtifacts: true, selector: lastSuccessful(), target: '.' + + stage('Evaluate metrics') { + sh "pip install matplotlib" + sh "cd train-eval && ./eval.py" + sh "./plot_metrics.py" + } + } + + stage('artifacts') { + echo 'saving artifacts' + archiveArtifacts 'metrics.txt', 'prediction.tsv', 'metrics.png' +} +} +} + diff --git a/JenkinsfileTrain b/JenkinsfileTrain index a3d613b..571b08c 100644 --- a/JenkinsfileTrain +++ b/JenkinsfileTrain @@ -1,6 +1,6 @@ node { checkout scm - def dockerimage = docker.build("train-image", "./train-eval") + def dockerimage = docker.build("train-image", "dockerfile_train") dockerimage.inside { stage('Preparation') { properties([ diff --git a/train-eval/eval.py b/train-eval/eval.py index 8368e49..936c717 100755 --- a/train-eval/eval.py +++ b/train-eval/eval.py @@ -45,7 +45,7 @@ print ("The accuracy is", acc) print ("The precission score is ", prec) print ("The recall score is ", recall) -file = open('metrics.txt', 'w') +file = open('metrics.txt', 'a') file.write(str(acc) + '\t' + str(prec) + '\t' + str(recall)) file.close() diff --git a/train-eval/learning.py b/train-eval/learning.py index 6ccaf74..8927fd5 100755 --- a/train-eval/learning.py +++ b/train-eval/learning.py @@ -3,7 +3,7 @@ import numpy as np import torch from torch import nn import pandas as pd -import subprocess +# import subprocess import sys from sklearn.model_selection import train_test_split @@ -47,7 +47,7 @@ if __name__ == "__main__": Y = df[['Survived']] X.loc[:,('Sex')].replace(['female', 'male'], [0,1], inplace=True) #categorical data transformed to - X_train, X_test, Y_train, Y_test = train_test_split(X,Y, random_state=45, test_size=0.2, shuffle=True) #split the date into train and test sets + X_train, X_test, Y_train, Y_test = train_test_split(X,Y, test_size=0.2, shuffle=True) #split the date into train and test sets testing_data = pd.concat([X_test, Y_test], axis=1) testing_data.to_csv('testing_data.csv', sep=',') diff --git a/train-eval/plot_metrics.py b/train-eval/plot_metrics.py new file mode 100755 index 0000000..4669e6c --- /dev/null +++ b/train-eval/plot_metrics.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 +import matplotlib +import matplotlib.pyplot as plt + +data = [] +with open('metrics.txt', 'r') as metrics: + for line in metrics: + data.append(line.strip().split('\t')) + + +# print(acc) +labels = ['accuracy','precision','recall'] +builds = [x for x in range(len(data))] +fig = plt.figure() +ax = fig.add_subplot(1,1,1) +for i in range(3): + ax.plot(builds, [data[x][i] for x in range(len(data))], label=labels[i]) +plt.legend() +plt.savefig('metrics.png') \ No newline at end of file