mlflow
This commit is contained in:
parent
866186c16e
commit
5e4ac37a43
11
MLproject
Normal file
11
MLproject
Normal file
@ -0,0 +1,11 @@
|
||||
name: ium_s434766-mlflow
|
||||
|
||||
docker_env:
|
||||
image: owczarczykp/ium_s434766:latest
|
||||
|
||||
entry_points:
|
||||
main:
|
||||
parameters:
|
||||
num_epochs: {type: int, default: 10}
|
||||
batch_size: {type: int, default: 16}
|
||||
command: "python3 lab8-mlflow.py -r {batch_size} {num_epochs}"
|
73
lab8-mlflow.py
Normal file
73
lab8-mlflow.py
Normal file
@ -0,0 +1,73 @@
|
||||
import torch
|
||||
import sys
|
||||
import mlflow
|
||||
import torch.nn.functional as F
|
||||
from torch import nn
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.metrics import accuracy_score, mean_squared_error
|
||||
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__()
|
||||
self.linear = nn.Linear(input_dim, output_dim)
|
||||
self.sigmoid = nn.Sigmoid()
|
||||
def forward(self, x):
|
||||
out = self.linear(x)
|
||||
return self.sigmoid(out)
|
||||
|
||||
with mlflow.start_run():
|
||||
data_train = pd.read_csv("data_train.csv")
|
||||
data_test = pd.read_csv("data_test.csv")
|
||||
data_val = pd.read_csv("data_val.csv")
|
||||
FEATURES = ['age','hypertension','heart_disease','ever_married', 'avg_glucose_level', 'bmi']
|
||||
|
||||
x_train = data_train[FEATURES].astype(np.float32)
|
||||
y_train = data_train['stroke'].astype(np.float32)
|
||||
|
||||
x_test = data_test[FEATURES].astype(np.float32)
|
||||
y_test = data_test['stroke'].astype(np.float32)
|
||||
|
||||
fTrain = torch.from_numpy(x_train.values)
|
||||
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 = 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
|
||||
|
||||
model = LogisticRegressionModel(input_dim, output_dim)
|
||||
|
||||
criterion = torch.nn.BCELoss(reduction='mean')
|
||||
optimizer = torch.optim.SGD(model.parameters(), lr = learning_rate)
|
||||
|
||||
for epoch in range(num_epochs):
|
||||
# print ("Epoch #",epoch)
|
||||
model.train()
|
||||
optimizer.zero_grad()
|
||||
# Forward pass
|
||||
y_pred = model(fTrain)
|
||||
# Compute Loss
|
||||
loss = criterion(y_pred, tTrain)
|
||||
# print(loss.item())
|
||||
# Backward pass
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
y_pred = model(fTest)
|
||||
# print("predicted Y value: ", y_pred.data)
|
||||
|
||||
torch.save(model.state_dict(), 'stroke.pth')
|
||||
|
||||
rmse = mean_squared_error(tTest, y_pred.detach().numpy())
|
||||
mlflow.log_metric("rmse", rmse)
|
||||
mlflow.log_param("Last loss", loss.item())
|
||||
mlflow.log_param("epochs", num_epochs)
|
||||
mlflow.log_param("batch size", batch_size)
|
||||
|
15
mlruns/0/0a44577d5489416ba432f0004c88ec5b/meta.yaml
Normal file
15
mlruns/0/0a44577d5489416ba432f0004c88ec5b/meta.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
artifact_uri: file:///home/przemek/ium_434766/mlruns/0/0a44577d5489416ba432f0004c88ec5b/artifacts
|
||||
end_time: 1621078832992
|
||||
entry_point_name: ''
|
||||
experiment_id: '0'
|
||||
lifecycle_stage: active
|
||||
name: ''
|
||||
run_id: 0a44577d5489416ba432f0004c88ec5b
|
||||
run_uuid: 0a44577d5489416ba432f0004c88ec5b
|
||||
source_name: ''
|
||||
source_type: 4
|
||||
source_version: ''
|
||||
start_time: 1621078832964
|
||||
status: 3
|
||||
tags: []
|
||||
user_id: przemek
|
1
mlruns/0/0a44577d5489416ba432f0004c88ec5b/metrics/rmse
Normal file
1
mlruns/0/0a44577d5489416ba432f0004c88ec5b/metrics/rmse
Normal file
@ -0,0 +1 @@
|
||||
1621078832990 0.8788978 0
|
@ -0,0 +1 @@
|
||||
7.942412376403809
|
@ -0,0 +1 @@
|
||||
16
|
1
mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/epochs
Normal file
1
mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/epochs
Normal file
@ -0,0 +1 @@
|
||||
5
|
@ -0,0 +1 @@
|
||||
866186c16e42c72886f5529feb1de754cdb93d54
|
@ -0,0 +1 @@
|
||||
lab8-mlflow.py
|
@ -0,0 +1 @@
|
||||
LOCAL
|
@ -0,0 +1 @@
|
||||
przemek
|
15
mlruns/0/8e73be609cf045c9a792e9712a5482d6/meta.yaml
Normal file
15
mlruns/0/8e73be609cf045c9a792e9712a5482d6/meta.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
artifact_uri: file:///home/przemek/ium_434766/mlruns/0/8e73be609cf045c9a792e9712a5482d6/artifacts
|
||||
end_time: 1621078794818
|
||||
entry_point_name: ''
|
||||
experiment_id: '0'
|
||||
lifecycle_stage: active
|
||||
name: ''
|
||||
run_id: 8e73be609cf045c9a792e9712a5482d6
|
||||
run_uuid: 8e73be609cf045c9a792e9712a5482d6
|
||||
source_name: ''
|
||||
source_type: 4
|
||||
source_version: ''
|
||||
start_time: 1621078794791
|
||||
status: 3
|
||||
tags: []
|
||||
user_id: przemek
|
1
mlruns/0/8e73be609cf045c9a792e9712a5482d6/metrics/rmse
Normal file
1
mlruns/0/8e73be609cf045c9a792e9712a5482d6/metrics/rmse
Normal file
@ -0,0 +1 @@
|
||||
1621078794815 0.87343794 0
|
@ -0,0 +1 @@
|
||||
11.738595962524414
|
@ -0,0 +1 @@
|
||||
16
|
1
mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/epochs
Normal file
1
mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/epochs
Normal file
@ -0,0 +1 @@
|
||||
5
|
@ -0,0 +1 @@
|
||||
866186c16e42c72886f5529feb1de754cdb93d54
|
@ -0,0 +1 @@
|
||||
lab8-mlflow.py
|
@ -0,0 +1 @@
|
||||
LOCAL
|
@ -0,0 +1 @@
|
||||
przemek
|
15
mlruns/0/a5a700d065624643b0e7e7addd6ec479/meta.yaml
Normal file
15
mlruns/0/a5a700d065624643b0e7e7addd6ec479/meta.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
artifact_uri: file:///home/przemek/ium_434766/mlruns/0/a5a700d065624643b0e7e7addd6ec479/artifacts
|
||||
end_time: 1621078798316
|
||||
entry_point_name: ''
|
||||
experiment_id: '0'
|
||||
lifecycle_stage: active
|
||||
name: ''
|
||||
run_id: a5a700d065624643b0e7e7addd6ec479
|
||||
run_uuid: a5a700d065624643b0e7e7addd6ec479
|
||||
source_name: ''
|
||||
source_type: 4
|
||||
source_version: ''
|
||||
start_time: 1621078798285
|
||||
status: 3
|
||||
tags: []
|
||||
user_id: przemek
|
1
mlruns/0/a5a700d065624643b0e7e7addd6ec479/metrics/rmse
Normal file
1
mlruns/0/a5a700d065624643b0e7e7addd6ec479/metrics/rmse
Normal file
@ -0,0 +1 @@
|
||||
1621078798313 0.09201313 0
|
@ -0,0 +1 @@
|
||||
0.3280356824398041
|
@ -0,0 +1 @@
|
||||
16
|
1
mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/epochs
Normal file
1
mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/epochs
Normal file
@ -0,0 +1 @@
|
||||
5
|
@ -0,0 +1 @@
|
||||
866186c16e42c72886f5529feb1de754cdb93d54
|
@ -0,0 +1 @@
|
||||
lab8-mlflow.py
|
@ -0,0 +1 @@
|
||||
LOCAL
|
@ -0,0 +1 @@
|
||||
przemek
|
15
mlruns/0/bb1356a5d8fd4a048612acedc090167f/meta.yaml
Normal file
15
mlruns/0/bb1356a5d8fd4a048612acedc090167f/meta.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
artifact_uri: file:///home/przemek/ium_434766/mlruns/0/bb1356a5d8fd4a048612acedc090167f/artifacts
|
||||
end_time: 1621078791156
|
||||
entry_point_name: ''
|
||||
experiment_id: '0'
|
||||
lifecycle_stage: active
|
||||
name: ''
|
||||
run_id: bb1356a5d8fd4a048612acedc090167f
|
||||
run_uuid: bb1356a5d8fd4a048612acedc090167f
|
||||
source_name: ''
|
||||
source_type: 4
|
||||
source_version: ''
|
||||
start_time: 1621078791105
|
||||
status: 3
|
||||
tags: []
|
||||
user_id: przemek
|
1
mlruns/0/bb1356a5d8fd4a048612acedc090167f/metrics/rmse
Normal file
1
mlruns/0/bb1356a5d8fd4a048612acedc090167f/metrics/rmse
Normal file
@ -0,0 +1 @@
|
||||
1621078791153 0.09705861 0
|
@ -0,0 +1 @@
|
||||
0.3212756812572479
|
@ -0,0 +1 @@
|
||||
16
|
1
mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/epochs
Normal file
1
mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/epochs
Normal file
@ -0,0 +1 @@
|
||||
5
|
@ -0,0 +1 @@
|
||||
866186c16e42c72886f5529feb1de754cdb93d54
|
@ -0,0 +1 @@
|
||||
lab8-mlflow.py
|
@ -0,0 +1 @@
|
||||
LOCAL
|
@ -0,0 +1 @@
|
||||
przemek
|
4
mlruns/0/meta.yaml
Normal file
4
mlruns/0/meta.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
artifact_location: file:///home/przemek/ium_434766/mlruns/0
|
||||
experiment_id: '0'
|
||||
lifecycle_stage: active
|
||||
name: Default
|
BIN
stroke.pth
BIN
stroke.pth
Binary file not shown.
Loading…
Reference in New Issue
Block a user