From 520206ef226b6f9203107206db038ddf974eff6a Mon Sep 17 00:00:00 2001 From: Alicja Szulecka <73056579+AliSzu@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:25:37 +0200 Subject: [PATCH] plot --- Jenkinsfile | 12 ++++++++++++ metrics.py | 9 ++++----- plot.py | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 plot.py diff --git a/Jenkinsfile b/Jenkinsfile index 3679bd2..9a9e8f3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,5 +42,17 @@ pipeline { } } } + + stage('Plot Accuracy') { + steps { + script { + def customImage = docker.build("custom-image") + customImage.inside { + sh 'python3 ./plot.py' + archiveArtifacts artifacts: 'accuracy.png', onlyIfSuccessful: true + } + } + } + } } } \ No newline at end of file diff --git a/metrics.py b/metrics.py index aedda85..1e966f3 100644 --- a/metrics.py +++ b/metrics.py @@ -18,8 +18,7 @@ rmse = np.sqrt(mean_squared_error(true_labels, predicted_labels)) with open(r'metrics.txt', 'a') as fp: fp.write(f"Accuracy: {accuracy}\n") - fp.write(f"Micro-average Precision: {precision_micro}\n") - fp.write(f"Micro-average Recall: {recall_micro}\n") - fp.write(f"Micro-average F1-score: {f1_micro}\n") - fp.write(f"RMSE: {rmse}\n") - fp.write("--------------------\n") \ No newline at end of file + fp.write(f"Precision: {precision_micro}\n") + fp.write(f"Recall: {recall_micro}\n") + fp.write(f"F1-score: {f1_micro}\n") + fp.write(f"RMSE: {rmse}\n") \ No newline at end of file diff --git a/plot.py b/plot.py new file mode 100644 index 0000000..5a2e22d --- /dev/null +++ b/plot.py @@ -0,0 +1,21 @@ +import matplotlib.pyplot as plt +import numpy as np + +accuracy = [] + +f = open("metrics.txt", "r") +for line in f: + parts = line.strip().split(' ') + if(parts[0] == 'Accuracy:'): + accuracy.append(float(parts[1])) + +y_values = np.arange(1, len(accuracy) + 1) + +plt.plot(y_values, accuracy, marker='o', linestyle='-', color='b') +plt.xlabel('Build Number') +plt.ylabel('Accuracy') +plt.title('Accuracy Plot') +plt.grid(True) +plt.show() + +plt.savefig('accuracy.png') \ No newline at end of file