IUM_06 - add evaluation Jenkinsfile, update Dockerfile, update models/Jenkinsfile, update predict.py script

This commit is contained in:
Paweł Łączkowski 2024-04-19 11:40:54 +02:00
parent 7a18968311
commit 2c0a3546d1
4 changed files with 57 additions and 1 deletions

View File

@ -20,6 +20,7 @@ WORKDIR /app
# Python scripts
COPY download_dataset.py ./
COPY get_stats.py ./
COPY NeuralNetwork.py ./
COPY create_model.py ./
COPY predict.py ./

40
evaluation/Jenkinsfile vendored Normal file
View File

@ -0,0 +1,40 @@
pipeline {
agent any
stages {
stage('Clone repository') {
steps {
checkout scm
}
}
stage('Copy artifacts') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
}
}
steps {
copyArtifacts(projectName: 's464863-training/main', filter: 'models/model.pth, datasets/test.csv', selector: lastSuccessful())
copyArtifacts(projectName: 's464863-evaluation/main', filter: 'metrics.csv', selector: lastSuccessful(), optional: true)
}
}
stage('Evaluate model') {
agent {
dockerfile {
filename 'Dockerfile'
reuseNode true
}
}
steps {
sh "chmod +x ./predict.py"
sh "python3 ./predict.py"
archiveArtifacts artifacts: 'predictions.csv, metrics.csv', onlyIfSuccessful: true
}
}
}
}

1
models/Jenkinsfile vendored
View File

@ -51,6 +51,7 @@ pipeline {
sh "chmod +x ./create_model.py"
sh "python3 ./create_model.py"
archiveArtifacts artifacts: 'models/model.pth, datasets/*', onlyIfSuccessful: true
build job: 's464863-evaluation/main', wait: false
}
}
}

View File

@ -3,8 +3,9 @@ import os
import pandas as pd
import numpy as np
from NeuralNetwork import NeuralNetwork
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score
from NeuralNetwork import NeuralNetwork
# Load model if it exists
if os.path.exists('./models/model.pth'):
@ -29,5 +30,18 @@ if os.path.exists('./models/model.pth'):
# Save predictions to CSV
pd.DataFrame(y_pred, columns=['Prediction']).to_csv('predictions.csv', index=False)
# Calculate metrics
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)
# Save metrics to CSV (append mode, if file exists, if not, create it)
if not os.path.exists('metrics.csv'):
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)
else:
raise FileNotFoundError('Model not found')