From f3f6ab7deed61b4dbd477e245e9665934b1cedae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=81=C4=85czkowski?= Date: Fri, 19 Apr 2024 12:02:09 +0200 Subject: [PATCH] IUM_06 - update evaluation/Jenkinsfile, update predict.py - metrics plot --- evaluation/Jenkinsfile | 2 +- predict.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/evaluation/Jenkinsfile b/evaluation/Jenkinsfile index 17fa89b..bb165b8 100644 --- a/evaluation/Jenkinsfile +++ b/evaluation/Jenkinsfile @@ -34,7 +34,7 @@ pipeline { steps { sh "chmod +x ./predict.py" sh "python3 ./predict.py" - archiveArtifacts artifacts: 'predictions.csv, metrics.csv', onlyIfSuccessful: true + archiveArtifacts artifacts: 'predictions.csv, metrics.csv, metrics.png', onlyIfSuccessful: true } } } diff --git a/predict.py b/predict.py index b4193a9..9905bac 100644 --- a/predict.py +++ b/predict.py @@ -5,6 +5,9 @@ import numpy as np from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score +import matplotlib.pyplot as plt +import seaborn as sns + from NeuralNetwork import NeuralNetwork # Load model if it exists @@ -42,6 +45,18 @@ if os.path.exists('./models/model.pth'): pd.DataFrame([[accuracy, precision, recall, f1]], columns=['Accuracy', 'Precision', 'Recall', 'F1']).to_csv('metrics.csv', index=False) else: # without header - pd.DataFrame([[accuracy, precision, recall, f1]], columns=['Accuracy', 'Precision', 'Recall', 'F1']).to_csv('metrics.csv', index=False, mode='a', header=False) + metrics = pd.read_csv('metrics.csv') + metrics = metrics._append({'Accuracy': accuracy, 'Precision': precision, 'Recall': recall, 'F1': f1}, ignore_index=True) + metrics.to_csv('metrics.csv', index=False, mode='a', header=False) + + # Plot metrics line chart + sns.set(style='whitegrid') + plt.figure(figsize=(8, 6)) + sns.lineplot(data=metrics) + plt.title('Metrics history') + plt.xlabel('History number') + plt.ylabel('Value') + plt.legend() + plt.savefig('metrics.png') else: raise FileNotFoundError('Model not found')