mlflow
This commit is contained in:
parent
8e853f42dc
commit
cbc41748d5
BIN
DEATH_EVENT.pth
BIN
DEATH_EVENT.pth
Binary file not shown.
78
IUM_08_mlflow.py
Normal file
78
IUM_08_mlflow.py
Normal file
@ -0,0 +1,78 @@
|
||||
import torch
|
||||
import sys
|
||||
from torch import nn
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import mlflow
|
||||
from sklearn.metrics import accuracy_score
|
||||
|
||||
np.set_printoptions(suppress=False)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
def readAndtrain(epochs, batch_size):
|
||||
train = pd.read_csv("train.csv")
|
||||
test = pd.read_csv("test.csv")
|
||||
|
||||
xtrain = train[['age','anaemia','creatinine_phosphokinase','diabetes', 'ejection_fraction', 'high_blood_pressure', 'platelets', 'serum_creatinine', 'serum_sodium', 'sex', 'smoking']].astype(np.float32)
|
||||
ytrain = train['DEATH_EVENT'].astype(np.float32)
|
||||
xtest = test[['age','anaemia','creatinine_phosphokinase','diabetes', 'ejection_fraction', 'high_blood_pressure', 'platelets', 'serum_creatinine', 'serum_sodium', 'sex', 'smoking']].astype(np.float32)
|
||||
ytest = test['DEATH_EVENT'].astype(np.float32)
|
||||
xTrain = torch.from_numpy(xtrain.values)
|
||||
yTrain = torch.from_numpy(ytrain.values.reshape(179,1))
|
||||
xTest = torch.from_numpy(xtest.values)
|
||||
yTest = torch.from_numpy(ytest.values)
|
||||
|
||||
learning_rate = 0.002
|
||||
input_dim = 11
|
||||
output_dim = 1
|
||||
|
||||
model = LogisticRegressionModel(input_dim, output_dim)
|
||||
model.load_state_dict(torch.load('DEATH_EVENT.pth'))
|
||||
|
||||
criterion = torch.nn.BCELoss(reduction='mean')
|
||||
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)
|
||||
|
||||
for epoch in range(epochs):
|
||||
# print ("Epoch #",epoch)
|
||||
model.train()
|
||||
optimizer.zero_grad()
|
||||
# Forward pass
|
||||
y_pred = model(xTrain)
|
||||
# Compute Loss
|
||||
loss = criterion(y_pred, yTrain)
|
||||
# print(loss.item())
|
||||
# Backward pass
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
|
||||
|
||||
torch.save(model.state_dict(), 'DEATH_EVENT.pth')
|
||||
prediction= model(xTest)
|
||||
|
||||
return prediction, loss.item(), yTest
|
||||
|
||||
print("accuracy_score", accuracy_score(yTest, np.argmax(prediction.detach().numpy(), axis=1)))
|
||||
# print("F1", f1_score(yTest, np.argmax(prediction.detach().numpy(), axis=1), average=None))
|
||||
|
||||
|
||||
batch_size = int(sys.argv[1]) if len(sys.argv) > 1 else 10
|
||||
epochs = int(sys.argv[2]) if len(sys.argv) > 2 else 5
|
||||
with mlflow.start_run():
|
||||
|
||||
prediction, loss, yTest = readAndtrain(epochs, batch_size)
|
||||
|
||||
mlflow.log_metric("accuracy_score", accuracy_score(yTest, np.argmax(prediction.detach().numpy(), axis=1)))
|
||||
mlflow.log_param("Last loss", loss)
|
||||
mlflow.log_param("epochs", epochs)
|
||||
mlflow.log_param("batch size", batch_size)
|
11
MLproject
Normal file
11
MLproject
Normal file
@ -0,0 +1,11 @@
|
||||
name: ium_s434766_mlflow_lab8
|
||||
|
||||
docker_env: my_env.yaml
|
||||
image: s434732/ium:latest
|
||||
|
||||
entry_points:
|
||||
main:
|
||||
parameters:
|
||||
epochs = 5
|
||||
batch_size = 10
|
||||
command: "python mlflow.py -r {train_size_param} {test_size_param} {epochs} {batch_size}"
|
BIN
__pycache__/IUM_08_mlflow.cpython-36.pyc
Normal file
BIN
__pycache__/IUM_08_mlflow.cpython-36.pyc
Normal file
Binary file not shown.
@ -9,7 +9,7 @@ from sacred.observers import FileStorageObserver
|
||||
|
||||
np.set_printoptions(suppress=False)
|
||||
|
||||
ex = Experiment("434732", interactive=False, save_git_info=False)
|
||||
ex = Experiment("ium_s434732", interactive=False, save_git_info=False)
|
||||
ex.observers.append(FileStorageObserver('ium_s434732/my_runs'))
|
||||
|
||||
@ex.config
|
||||
|
15
mlruns/0/9031aa80d3b948fca55268f6f0b0c117/meta.yaml
Normal file
15
mlruns/0/9031aa80d3b948fca55268f6f0b0c117/meta.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
artifact_uri: file:///mnt/c/Users/micha/Desktop/MAGISTER/In%C5%BCyniera%20uczenia%20maszynowego/git/ium_434732/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/artifacts
|
||||
end_time: 1621170671245
|
||||
entry_point_name: ''
|
||||
experiment_id: '0'
|
||||
lifecycle_stage: active
|
||||
name: ''
|
||||
run_id: 9031aa80d3b948fca55268f6f0b0c117
|
||||
run_uuid: 9031aa80d3b948fca55268f6f0b0c117
|
||||
source_name: ''
|
||||
source_type: 4
|
||||
source_version: ''
|
||||
start_time: 1621170670730
|
||||
status: 4
|
||||
tags: []
|
||||
user_id: naapster
|
@ -0,0 +1 @@
|
||||
1621170671205 0.55 0
|
@ -0,0 +1 @@
|
||||
8e853f42dcd05f226e6f42086c9778fc3c9adcbf
|
@ -0,0 +1 @@
|
||||
IUM_08_mlflow.py
|
@ -0,0 +1 @@
|
||||
LOCAL
|
@ -0,0 +1 @@
|
||||
naapster
|
15
mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/meta.yaml
Normal file
15
mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/meta.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
artifact_uri: file:///mnt/c/Users/micha/Desktop/MAGISTER/In%C5%BCyniera%20uczenia%20maszynowego/git/ium_434732/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/artifacts
|
||||
end_time: 1621171451245
|
||||
entry_point_name: ''
|
||||
experiment_id: '0'
|
||||
lifecycle_stage: active
|
||||
name: ''
|
||||
run_id: b5ca2a8b58714cbdb4203ff66b024557
|
||||
run_uuid: b5ca2a8b58714cbdb4203ff66b024557
|
||||
source_name: ''
|
||||
source_type: 4
|
||||
source_version: ''
|
||||
start_time: 1621171450331
|
||||
status: 3
|
||||
tags: []
|
||||
user_id: naapster
|
@ -0,0 +1 @@
|
||||
1621171451102 0.55 0
|
@ -0,0 +1 @@
|
||||
27.758575439453125
|
@ -0,0 +1 @@
|
||||
10
|
1
mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/epochs
Normal file
1
mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/epochs
Normal file
@ -0,0 +1 @@
|
||||
5
|
@ -0,0 +1 @@
|
||||
8e853f42dcd05f226e6f42086c9778fc3c9adcbf
|
@ -0,0 +1 @@
|
||||
IUM_08_mlflow.py
|
@ -0,0 +1 @@
|
||||
LOCAL
|
@ -0,0 +1 @@
|
||||
naapster
|
4
mlruns/0/meta.yaml
Normal file
4
mlruns/0/meta.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
artifact_location: file:///mnt/c/Users/micha/Desktop/MAGISTER/In%C5%BCyniera%20uczenia%20maszynowego/git/ium_434732/mlruns/0
|
||||
experiment_id: '0'
|
||||
lifecycle_stage: active
|
||||
name: Default
|
Loading…
Reference in New Issue
Block a user