From 0d495bc36fc677a8294783c5c4de5a71d247e58d Mon Sep 17 00:00:00 2001 From: gedin Date: Wed, 24 May 2023 16:45:29 +0200 Subject: [PATCH] plotting and eval metrics --- JenkinsfileEval | 20 ++++++++++++++++++++ train-eval/eval.py | 2 +- train-eval/plot_metrics.py | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 JenkinsfileEval create mode 100755 train-eval/plot_metrics.py 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/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/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