IUM_06 - update evaluation/Jenkinsfile, update predict.py - metrics plot

This commit is contained in:
Paweł Łączkowski 2024-04-19 12:02:09 +02:00
parent 697e0ad2df
commit f3f6ab7dee
2 changed files with 17 additions and 2 deletions

View File

@ -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
}
}
}

View File

@ -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')