Add evaluation files
This commit is contained in:
parent
a866992b19
commit
62539bf6db
@ -10,3 +10,4 @@ RUN pip3 install numpy
|
||||
WORKDIR /app
|
||||
|
||||
COPY ./training.py ./
|
||||
COPY ./evaluation.py ./
|
||||
|
27
evaluation.Jenkinsfile
Normal file
27
evaluation.Jenkinsfile
Normal file
@ -0,0 +1,27 @@
|
||||
pipeline {
|
||||
agent {
|
||||
dockerfile true
|
||||
}
|
||||
parameters {
|
||||
buildSelector(
|
||||
defaultSelector: lastSuccessful(),
|
||||
description: 'Which build to use for copying artifacts',
|
||||
name: 'BUILD_SELECTOR'
|
||||
)
|
||||
}
|
||||
stages {
|
||||
stage('Check out from version control') {
|
||||
steps {
|
||||
checkout([$class: 'GitSCM', branches: [[name: '*/training_and_evaluation']], extensions: [], userRemoteConfigs: [[credentialsId: 's444421', url: 'https://git.wmi.amu.edu.pl/s444421/ium_444421.git']]])
|
||||
}
|
||||
}
|
||||
stage('Script') {
|
||||
steps {
|
||||
copyArtifacts filter: '*', projectName:'s444421-training/training_and_evaluation', selector: buildParameter('BUILD_SELECTOR')
|
||||
copyArtifacts filter: '*', projectName:'s444421-evaluation/training_and_evaluation', optional: true
|
||||
sh 'ipython ./evaluation.py'
|
||||
archiveArtifacts artifacts: 'build_accuracy.txt'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
73
evaluation.py
Normal file
73
evaluation.py
Normal file
@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from sklearn.metrics import accuracy_score
|
||||
import torch
|
||||
from torch import nn, optim
|
||||
import torch.nn.functional as F
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
class Net(nn.Module):
|
||||
def __init__(self, n_features):
|
||||
super(Net, self).__init__()
|
||||
self.fc1 = nn.Linear(n_features, 5)
|
||||
self.fc2 = nn.Linear(5, 3)
|
||||
self.fc3 = nn.Linear(3, 1)
|
||||
def forward(self, x):
|
||||
x = F.relu(self.fc1(x))
|
||||
x = F.relu(self.fc2(x))
|
||||
return torch.sigmoid(self.fc3(x))
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
X_test = pd.read_csv('X_test.csv')
|
||||
y_test = pd.read_csv('y_test.csv')
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
X_test = torch.from_numpy(np.array(X_test)).float()
|
||||
y_test = torch.squeeze(torch.from_numpy(y_test.values).float())
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
||||
X_test = X_test.to(device)
|
||||
y_test = y_test.to(device)
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
net = torch.load('model.pth')
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
y_pred = net(X_test)
|
||||
y_pred = y_pred.ge(.5).view(-1).cpu()
|
||||
y_test = y_test.cpu()
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
accuracy = accuracy_score(y_test, y_pred)
|
||||
with open('build_accuracy.txt', 'a') as file:
|
||||
file.write(str(accuracy))
|
||||
file.write('\n')
|
||||
|
Loading…
Reference in New Issue
Block a user