jobs
Some checks reported errors
s434766-training/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
s434766 2021-05-07 21:30:35 +02:00
parent e4b54adf07
commit 3dfc1beec8
9 changed files with 118 additions and 98 deletions

View File

@ -1,10 +1,10 @@
FROM ubuntu:latest
RUN apt-get update && apt-get install -y python3-pip && pip3 install setuptools && pip3 install numpy && pip3 install pandas && pip3 install wget && pip3 install scikit-learn && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y python3-pip && pip3 install setuptools && pip3 install numpy && pip3 install pandas && pip3 install wget && pip3 install scikit-learn && pip3 install matplotlib && rm -rf /var/lib/apt/lists/*
RUN pip3 install torch torchvision torchaudio
WORKDIR /app
COPY ./create.py ./
COPY ./stats.py ./
COPY ./stroke-pytorch.py ./
COPY ./stroke-pytorch-eval.py ./

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,11 @@
FROM ubuntu:latest
RUN apt-get update && apt-get install -y python3-pip && pip3 install setuptools && pip3 install numpy && pip3 install pandas && pip3 install wget && pip3 install scikit-learn && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y python3-pip && pip3 install setuptools && pip3 install numpy && pip3 install pandas && pip3 install wget && pip3 install scikit-learn && pip3 install matplotlib && rm -rf /var/lib/apt/lists/*
RUN pip3 install torch torchvision torchaudio
WORKDIR /app
COPY ./create.py ./
COPY ./stats.py ./
COPY ./stroke-pytorch.py ./
COPY ./stroke-pytorch-eval.py ./

View File

@ -0,0 +1,32 @@
pipeline {
agent {
dockerfile true
}
stages {
stage('checkout') {
steps {
git 'https://git.wmi.amu.edu.pl/s434766/ium_434766.git'
copyArtifacts fingerprintArtifacts: true, projectName: 's434766-create-dataset'
copyArtifacts fingerprintArtifacts: true, projectName: 's434766-training'
}
}
stage('Docker'){
steps{
sh 'python3 "./stroke-pytorch-eval.py" >> eval.txt'
}
}
stage('archiveArtifacts') {
steps {
archiveArtifacts 'eval.txt'
}
post {
success {
emailext body: 'Evaluation of stroke predictions is finished',
subject: 's434766 evaluation finished',
to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms'
}
}
}
}
}

View File

@ -11,18 +11,20 @@ pipeline {
}
stage('Docker'){
steps{
sh 'python3 "./stroke-pytorch.py" > model.txt'
}
}
stage('checkout: Check out from version control') {
steps {
git 'https://git.wmi.amu.edu.pl/s434766/ium_434766.git'
sh 'python3 "./stroke-pytorch.py" ${BATCH_SIZE} ${EPOCHS} > pred.txt'
}
}
stage('archiveArtifacts') {
steps {
archiveArtifacts 'model.txt'
archiveArtifacts 'pred.txt'
archiveArtifacts 'stroke.pkl'
}
post {
success {
emailext body: 'Training of stroke predictions is finished',
subject: 's434766 training finished',
to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms'
}
}
}
}

50
stroke-pytorch-eval.py Normal file
View File

@ -0,0 +1,50 @@
import torch
import torch.nn as nn
import numpy as np
from os import path
import torch.nn.functional as F
from torch import nn
from torch.autograd import Variable
import torchvision.transforms as transforms
import pandas as pd
from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_squared_error
from sklearn.metrics import classification_report
import matplotlib.pyplot as plt
class LogisticRegressionModel(nn.Module):
def __init__(self, input_dim, output_dim):
super(LogisticRegressionModel, self).__init__()
self.linear = nn.Linear(input_dim, output_dim)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
out = self.linear(x)
return self.sigmoid(out)
np.set_printoptions(suppress=False)
data_test = pd.read_csv("data_test.csv")
FEATURES = ['age','hypertension','heart_disease','ever_married', 'avg_glucose_level', 'bmi']
x_test = data_test[FEATURES].astype(np.float32)
y_test = data_test['stroke'].astype(np.float32)
fTest= torch.from_numpy(x_test.values)
tTest = torch.from_numpy(y_test.values)
model = LogisticRegressionModel(6,1)
model.load_state_dict(torch.load('stroke.pth'))
y_pred = model(fTest)
rmse = mean_squared_error(tTest, y_pred.detach().numpy())
acc = accuracy_score(tTest, np.argmax(y_pred.detach().numpy(), axis=1))
print('-' * 60)
print(classification_report(tTest, y_pred.detach().numpy().round()))
print(f" RMSE: {rmse}")
print(f" Accuracy: {acc}")
print('-' * 60)

View File

@ -1,4 +1,5 @@
import torch
import sys
import torch.nn.functional as F
from torch import nn
from torch.autograd import Variable
@ -9,6 +10,8 @@ from sklearn.metrics import accuracy_score
import numpy as np
import pandas as pd
np.set_printoptions(suppress=False)
class LogisticRegressionModel(nn.Module):
def __init__(self, input_dim, output_dim):
super(LogisticRegressionModel, self).__init__()
@ -35,9 +38,8 @@ tTrain = torch.from_numpy(y_train.values.reshape(2945,1))
fTest= torch.from_numpy(x_test.values)
tTest = torch.from_numpy(y_test.values)
batch_size = 95
n_iters = 1000
num_epochs = int(n_iters / (len(x_train) / batch_size))
batch_size = int(sys.argv[1]) if len(sys.argv) > 1 else 16
num_epochs = int(sys.argv[2]) if len(sys.argv) > 2 else 5
learning_rate = 0.001
input_dim = 6
output_dim = 1
@ -48,7 +50,7 @@ criterion = torch.nn.BCELoss(reduction='mean')
optimizer = torch.optim.SGD(model.parameters(), lr = learning_rate)
for epoch in range(num_epochs):
print ("Epoch #",epoch)
# print ("Epoch #",epoch)
model.train()
optimizer.zero_grad()
# Forward pass
@ -64,6 +66,4 @@ for epoch in range(num_epochs):
y_pred = model(fTest)
print("predicted Y value: ", y_pred.data)
print ("The accuracy is", accuracy_score(tTest, np.argmax(y_pred.detach().numpy(), axis=1)))
torch.save(model, 'stroke.pkl')
torch.save(model.state_dict(), 'stroke.pth')

Binary file not shown.

BIN
stroke.pth Normal file

Binary file not shown.