From a6f8a4fe789b46242f67be8b5f32a2e99eb7917b Mon Sep 17 00:00:00 2001 From: Szymon Bartanowicz Date: Wed, 15 May 2024 00:07:51 +0200 Subject: [PATCH] evaluation --- Jenkinsfile | 77 +++++++++++++++++++++++++++++++++++------------------ metrics.py | 24 +++++++++++++++++ plot.py | 22 +++++++++++++++ 3 files changed, 97 insertions(+), 26 deletions(-) create mode 100644 metrics.py create mode 100644 plot.py diff --git a/Jenkinsfile b/Jenkinsfile index 678883c..ca32352 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,37 +1,62 @@ pipeline { - agent any - - parameters { - string(name: 'CUTOFF', defaultValue: '100', description: 'Ilość wierszy do odcięcia') - string(name: 'KAGGLE_USERNAME', defaultValue: '', description: 'Kaggle username') - password(name: 'KAGGLE_KEY', defaultValue: '', description: 'Kaggle API key') + agent { + dockerfile true } + triggers { + upstream(upstreamProjects: 's464937-training/training', threshold: hudson.model.Result.SUCCESS) + } + + parameters { + buildSelector(defaultSelector: lastSuccessful(), description: 'Which build to use for copying artifacts', name: 'BUILD_SELECTOR') + gitParameter branchFilter: 'origin/(.*)', defaultValue: 'training', name: 'BRANCH', type: 'PT_BRANCH' + } + stages { - stage('Clone repo') { + stage('Clone Repository') { steps { - git branch: "main", url: "https://git.wmi.amu.edu.pl/s464937/ium_464937" + git branch: 'evaluation', url: "https://git.wmi.amu.edu.pl/s464937/ium_464937" } } + stage('Copy Dataset Artifacts') { + steps { + copyArtifacts filter: 'data/dev.csv,data/test.csv,data/train.csv', projectName: 'z-s464937-create-dataset', selector: buildParameter('BUILD_SELECTOR') + } + } + stage('Copy Training Artifacts') { + steps { + copyArtifacts filter: 'powerlifting_model.h5', projectName: 's464937-training/' + params.BRANCH, selector: buildParameter('BUILD_SELECTOR') + } + } + stage('Copy Evaluation Artifacts') { + steps { + copyArtifacts filter: 'metrics.txt', projectName: '_s464937-evaluation/evaluation', selector: buildParameter('BUILD_SELECTOR'), optional: true + } + } + stage("Run predictions") { + steps { + sh "chmod +x ./predict.py" + sh "python3 ./predict.py" + archiveArtifacts artifacts: 'powerlifting_test_predictions.csv', onlyIfSuccessful: true + } + } + stage('Run metrics') { + steps { + sh 'chmod +x ./metrics.py' + sh "python3 ./metrics.py ${currentBuild.number}" + } + } - stage('Download and preprocess') { - environment { - KAGGLE_USERNAME = "szymonbartanowicz" - KAGGLE_KEY = "4692239eb65f20ec79f9a59ef30e67eb" - } - steps { - withEnv([ - "KAGGLE_USERNAME=${env.KAGGLE_USERNAME}", - "KAGGLE_KEY=${env.KAGGLE_KEY}" - ]) { - sh "bash ./script1.sh ${params.CUTOFF}" - } - } + stage('Run plot') { + steps { + sh 'chmod +x ./plot.py' + sh 'python3 ./plot.py' + } } - stage('Archive') { - steps { - archiveArtifacts artifacts: 'data/*', onlyIfSuccessful: true - } + stage('Archive Artifacts') { + steps { + archiveArtifacts artifacts: '*', onlyIfSuccessful: true + } } } -} \ No newline at end of file +} diff --git a/metrics.py b/metrics.py new file mode 100644 index 0000000..c124b1f --- /dev/null +++ b/metrics.py @@ -0,0 +1,24 @@ +# import pandas as pd +# from sklearn.metrics import accuracy_score, precision_recall_fscore_support, mean_squared_error +# from math import sqrt +# import sys +# +# data = pd.read_csv('powerlifting_test_predictions.csv') +# y_pred = data['Predictions'] +# y_test = data['Actual'] +# y_test_binary = (y_test >= 3).astype(int) +# +# build_number = sys.argv[1] +# +# accuracy = accuracy_score(y_test_binary, y_pred.round()) +# precision, recall, f1, _ = precision_recall_fscore_support(y_test_binary, y_pred.round(), average='micro') +# rmse = sqrt(mean_squared_error(y_test, y_pred)) +# +# print(f'Accuracy: {accuracy}') +# print(f'Micro-avg Precision: {precision}') +# print(f'Micro-avg Recall: {recall}') +# print(f'F1 Score: {f1}') +# print(f'RMSE: {rmse}') + +with open(r"metrics.txt", "a") as f: + f.write(f"{123},{1}\n") \ No newline at end of file diff --git a/plot.py b/plot.py new file mode 100644 index 0000000..72eaa81 --- /dev/null +++ b/plot.py @@ -0,0 +1,22 @@ +import matplotlib.pyplot as plt + +def main(): + accuracy = [] + build_numbers = [] + + with open("maetrics.txt") as f: + for line in f: + accuracy.append(float(line.split(",")[0])) + build_numbers.append(int(line.split(",")[1])) + + plt.plot(build_numbers, accuracy) + plt.xlabel("Build Number") + plt.ylabel("Accuracy") + plt.title("Accuracy of the model over time") + plt.xticks(range(min(build_numbers), max(build_numbers) + 1)) + plt.show() + + plt.savefig("plot.png") + +if __name__ == "__main__": + main() \ No newline at end of file