Lr model + docker
This commit is contained in:
parent
97a1fc9a28
commit
1d0cca3825
32
learning/Jenkinsfile
vendored
Normal file
32
learning/Jenkinsfile
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
pipeline {
|
||||
agent {
|
||||
dockerfile true
|
||||
}
|
||||
stages {
|
||||
stage('Copy Archive') {
|
||||
steps {
|
||||
script {
|
||||
step ([$class: 'CopyArtifact',
|
||||
projectName: 's434700-create-dataset',
|
||||
filter: '*.csv',
|
||||
target: 'datasets'])
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('checkout: Check out from version control') {
|
||||
steps {
|
||||
git 'https://git.wmi.amu.edu.pl/s434700/ium_s434700.git'
|
||||
}
|
||||
}
|
||||
stage('learning') {
|
||||
steps {
|
||||
sh 'python ./learning/ml.py'
|
||||
}
|
||||
}
|
||||
stage('archiveArtifacts') {
|
||||
steps {
|
||||
archiveArtifacts 'model.pt'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
64
learning/ml.py
Normal file
64
learning/ml.py
Normal file
@ -0,0 +1,64 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
import torch
|
||||
import datetime
|
||||
from torch.autograd import Variable
|
||||
|
||||
|
||||
INPUT_DIM = 1
|
||||
OUTPUT_DIM = 1
|
||||
LEARNING_RATE = 0.01
|
||||
EPOCHS = 100
|
||||
|
||||
|
||||
dataset = pd.read_csv('datasets/train_set.csv')
|
||||
|
||||
|
||||
x_values = [datetime.datetime.strptime(
|
||||
item, "%Y-%m-%d").month for item in dataset['date'].values]
|
||||
x_train = np.array(x_values, dtype=np.float32)
|
||||
x_train = x_train.reshape(-1, 1)
|
||||
|
||||
y_values = [min(dataset['result_1'].values[i]/dataset['result_2'].values[i], dataset['result_2'].values[i] /
|
||||
dataset['result_1'].values[i]) for i in range(len(dataset['result_1'].values))]
|
||||
y_train = np.array(y_values, dtype=np.float32)
|
||||
y_train = y_train.reshape(-1, 1)
|
||||
|
||||
|
||||
class LinearRegression(torch.nn.Module):
|
||||
def __init__(self, inputSize, outputSize):
|
||||
super(LinearRegression, self).__init__()
|
||||
self.linear = torch.nn.Linear(inputSize, outputSize)
|
||||
|
||||
def forward(self, x):
|
||||
out = self.linear(x)
|
||||
return out
|
||||
|
||||
|
||||
model = LinearRegression(INPUT_DIM, OUTPUT_DIM)
|
||||
|
||||
|
||||
criterion = torch.nn.MSELoss()
|
||||
optimizer = torch.optim.SGD(model.parameters(), lr=LEARNING_RATE)
|
||||
|
||||
for epoch in range(EPOCHS):
|
||||
inputs = Variable(torch.from_numpy(x_train))
|
||||
labels = Variable(torch.from_numpy(y_train))
|
||||
|
||||
optimizer.zero_grad()
|
||||
|
||||
outputs = model(inputs)
|
||||
|
||||
loss = criterion(outputs, labels)
|
||||
print(loss)
|
||||
loss.backward()
|
||||
|
||||
optimizer.step()
|
||||
|
||||
print('epoch {}, loss {}'.format(epoch, loss.item()))
|
||||
|
||||
torch.save(model.state_dict(), 'model.pt')
|
19
ml.py
19
ml.py
@ -1,19 +0,0 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
|
||||
dataset = pd.read_csv('./train_set.csv')
|
||||
print(dataset.head())
|
||||
|
||||
print(dataset.map_winner)
|
||||
|
||||
# teams1 = dataset['team_1'].cat.codes.values
|
||||
# teams2 = dataset['team_2'].cat.codes.values
|
||||
|
||||
print(dataset.dtypes)
|
||||
|
||||
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
||||
print(device)
|
Loading…
Reference in New Issue
Block a user