This commit is contained in:
Mateusz 2024-05-04 15:25:54 +02:00
parent a6be9a7295
commit ee4c1adab2
3 changed files with 61 additions and 36 deletions

60
Jenkinsfile vendored
View File

@ -1,54 +1,56 @@
pipeline { pipeline {
agent any agent {
dockerfile true
}
triggers {
upstream(upstreamProjects: 's464913-training/training', threshold: hudson.model.Result.SUCCESS)
}
parameters { parameters {
string ( buildSelector(
defaultValue: 'vskyper', defaultSelector: lastSuccessful(),
description: 'Kaggle username', description: 'Which build to use for copying artifacts',
name: 'KAGGLE_USERNAME', name: 'BUILD_SELECTOR'
trim: false
)
password (
defaultValue: '',
description: 'Kaggle API key',
name: 'KAGGLE_KEY',
) )
} }
stages { stages {
stage('Clone Repository') { stage('Clone Repository') {
steps { steps {
git branch: 'main', url: 'https://git.wmi.amu.edu.pl/s464913/ium_464913.git' git branch: 'evaluation', url: 'https://git.wmi.amu.edu.pl/s464913/ium_464913.git'
} }
} }
stage('Download dataset') { stage('Copy Artifacts from dataset job') {
steps { steps {
withEnv(["KAGGLE_USERNAME=${params.KAGGLE_USERNAME}", "KAGGLE_KEY=${params.KAGGLE_KEY}"]) { copyArtifacts filter: 'data/*', projectName: 'z-s464913-create-dataset', selector: buildParameter('BUILD_SELECTOR')
sh 'pip install kaggle'
sh 'kaggle datasets download -d mlg-ulb/creditcardfraud'
sh 'unzip -o creditcardfraud.zip'
sh 'rm creditcardfraud.zip'
}
} }
} }
stage('Run create-dataset script') { stage('Copy Artifacts from training job') {
agent {
dockerfile {
reuseNode true
}
}
steps { steps {
sh 'chmod +x create-dataset.py' copyArtifacts filter: 'model/*', projectName: 's464913-training/training', selector: buildParameter('BUILD_SELECTOR')
sh 'python3 ./create-dataset.py' }
}
stage('Run predict script') {
steps {
sh 'chmod +x predict.py'
sh 'python3 ./predict.py'
}
}
stage('Run metrics script') {
steps {
sh 'chmod +x metrics.py'
sh 'python3 ./metrics.py'
} }
} }
stage('Archive Artifacts') { stage('Archive Artifacts') {
steps { steps {
archiveArtifacts artifacts: 'data/*', onlyIfSuccessful: true archiveArtifacts artifacts: 'evaluation/*', onlyIfSuccessful: true
} }
} }
} }

27
metrics.py Normal file
View File

@ -0,0 +1,27 @@
from sklearn.metrics import (
accuracy_score,
precision_score,
recall_score,
f1_score,
mean_squared_error,
)
import numpy as np
import pandas as pd
def main():
y_test = pd.read_csv("data/y_test.csv")
y_pred = pd.read_csv("evaluation/y_pred.csv")
accuracy = accuracy_score(y_test, y_pred)
precision_micro = precision_score(y_test, y_pred, average="micro")
recall_micro = recall_score(y_test, y_pred, average="micro")
with open(r"evaluation/metrics.txt", "a") as f:
f.write(f"Accuracy: {accuracy}\n")
f.write(f"Micro-average Precision: {precision_micro}\n")
f.write(f"Micro-average Recall: {recall_micro}\n")
if __name__ == "__main__":
main()

View File

@ -11,17 +11,13 @@ import numpy as np
def main(): def main():
model = load_model("model/model.keras") model = load_model("model/model.keras")
X_test = pd.read_csv("data/X_test.csv") X_test = pd.read_csv("data/X_test.csv")
y_test = pd.read_csv("data/y_test.csv")
y_pred = model.predict(X_test) y_pred = model.predict(X_test)
y_pred = y_pred >= 0.5 y_pred = y_pred >= 0.5
np.savetxt("data/y_pred.csv", y_pred, delimiter=",")
cm = confusion_matrix(y_test, y_pred) os.makedirs("evaluation", exist_ok=True)
print( os.system("rm -rf evaluation/*")
"Recall metric in the testing dataset: ", np.savetxt("evaluation/y_pred.csv", y_pred, delimiter=",")
cm[1, 1] / (cm[1, 0] + cm[1, 1]),
)
if __name__ == "__main__": if __name__ == "__main__":