s
This commit is contained in:
parent
cca5f3ea56
commit
8be83d4714
45
JenkinsfileEvaluate
Normal file
45
JenkinsfileEvaluate
Normal file
@ -0,0 +1,45 @@
|
||||
pipeline {
|
||||
agent {
|
||||
docker {
|
||||
image 'python:3.11'
|
||||
args '-v /root/.cache:/root/.cache -u root'
|
||||
}
|
||||
}
|
||||
parameters {
|
||||
gitParameter name: 'BRANCH', type: 'PT_BRANCH'
|
||||
buildSelector(name: 'BUILD_NUMBER', description: 'Wybierz numer buildu', defaultSelector: lastSuccessful())
|
||||
}
|
||||
stages {
|
||||
stage('Preparation') {
|
||||
steps {
|
||||
sh 'pip install pandas tensorflow scikit-learn matplotlib'
|
||||
}
|
||||
}
|
||||
stage('Pobierz dane') {
|
||||
steps {
|
||||
script {
|
||||
copyArtifacts(projectName: 's487187-create-dataset', fingerprintArtifacts: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Pobierz model') {
|
||||
steps {
|
||||
script {
|
||||
copyArtifacts(projectName: 's487187-training', selector: specific("${params.BUILD_NUMBER}"), filter: 'model.h5', fingerprintArtifacts: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Ewaluuj model') {
|
||||
steps {
|
||||
script {
|
||||
sh "python3 evaluate.py"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Zarchiwizuj wyniki') {
|
||||
steps {
|
||||
archiveArtifacts artifacts: 'metrics.txt,plot.png', fingerprint: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
43
evaluate.py
Normal file
43
evaluate.py
Normal file
@ -0,0 +1,43 @@
|
||||
import tensorflow as tf
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from sklearn.preprocessing import MinMaxScaler
|
||||
from sklearn.metrics import accuracy_score, f1_score, mean_squared_error
|
||||
import matplotlib.pyplot as plt
|
||||
import os
|
||||
|
||||
model = tf.keras.models.load_model('model.h5')
|
||||
|
||||
|
||||
test_data = pd.read_csv('test_data.csv', sep=';')
|
||||
test_data = pd.get_dummies(test_data, columns=['Sex', 'Medal'])
|
||||
test_data = test_data.drop(columns=['Name', 'Team', 'NOC', 'Games', 'Year', 'Season', 'City', 'Sport', 'Event'])
|
||||
|
||||
scaler = MinMaxScaler()
|
||||
test_data = pd.DataFrame(scaler.fit_transform(test_data), columns=test_data.columns)
|
||||
|
||||
X_test = test_data.filter(regex='Sex|Age')
|
||||
y_test = test_data.filter(regex='Medal')
|
||||
y_test = pd.get_dummies(y_test)
|
||||
|
||||
X_test = X_test.fillna(0)
|
||||
y_test = y_test.fillna(0)
|
||||
|
||||
y_pred = model.predict(X_test)
|
||||
|
||||
top_1_accuracy = tf.keras.metrics.categorical_accuracy(y_test, y_pred)
|
||||
top_5_accuracy = tf.keras.metrics.top_k_categorical_accuracy(y_test, y_pred, k=5)
|
||||
|
||||
metrics_file = 'metrics.txt'
|
||||
if os.path.exists(metrics_file):
|
||||
metrics_df = pd.read_csv(metrics_file)
|
||||
else:
|
||||
metrics_df = pd.DataFrame(columns=['top_1_accuracy', 'top_5_accuracy'])
|
||||
metrics_df = metrics_df.append({'top_1_accuracy': np.mean(top_1_accuracy), 'top_5_accuracy': np.mean(top_5_accuracy)}, ignore_index=True)
|
||||
metrics_df.to_csv(metrics_file, index=False)
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.plot(metrics_df['top_1_accuracy'], label='Top-1 Accuracy')
|
||||
plt.plot(metrics_df['top_5_accuracy'], label='Top-5 Accuracy')
|
||||
plt.legend()
|
||||
plt.savefig('plot.png')
|
Loading…
Reference in New Issue
Block a user