diff --git a/MLproject b/MLproject new file mode 100644 index 0000000..5f14ffa --- /dev/null +++ b/MLproject @@ -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}" \ No newline at end of file diff --git a/lab8-mlflow.py b/lab8-mlflow.py new file mode 100644 index 0000000..e713915 --- /dev/null +++ b/lab8-mlflow.py @@ -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) + diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/meta.yaml b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/meta.yaml new file mode 100644 index 0000000..78e673f --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/meta.yaml @@ -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 diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/metrics/rmse b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/metrics/rmse new file mode 100644 index 0000000..c863704 --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/metrics/rmse @@ -0,0 +1 @@ +1621078832990 0.8788978 0 diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/Last loss b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/Last loss new file mode 100644 index 0000000..ca8da94 --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/Last loss @@ -0,0 +1 @@ +7.942412376403809 \ No newline at end of file diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/batch size b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/batch size new file mode 100644 index 0000000..19c7bdb --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/batch size @@ -0,0 +1 @@ +16 \ No newline at end of file diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/epochs b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/epochs new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/params/epochs @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.git.commit b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.git.commit new file mode 100644 index 0000000..109cacc --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.git.commit @@ -0,0 +1 @@ +866186c16e42c72886f5529feb1de754cdb93d54 \ No newline at end of file diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.name b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.name new file mode 100644 index 0000000..cced201 --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.name @@ -0,0 +1 @@ +lab8-mlflow.py \ No newline at end of file diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.type b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.type new file mode 100644 index 0000000..0c2c1fe --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.source.type @@ -0,0 +1 @@ +LOCAL \ No newline at end of file diff --git a/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.user b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.user new file mode 100644 index 0000000..710cb86 --- /dev/null +++ b/mlruns/0/0a44577d5489416ba432f0004c88ec5b/tags/mlflow.user @@ -0,0 +1 @@ +przemek \ No newline at end of file diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/meta.yaml b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/meta.yaml new file mode 100644 index 0000000..e28ec6c --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/meta.yaml @@ -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 diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/metrics/rmse b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/metrics/rmse new file mode 100644 index 0000000..196f663 --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/metrics/rmse @@ -0,0 +1 @@ +1621078794815 0.87343794 0 diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/Last loss b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/Last loss new file mode 100644 index 0000000..b1c5057 --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/Last loss @@ -0,0 +1 @@ +11.738595962524414 \ No newline at end of file diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/batch size b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/batch size new file mode 100644 index 0000000..19c7bdb --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/batch size @@ -0,0 +1 @@ +16 \ No newline at end of file diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/epochs b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/epochs new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/params/epochs @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.git.commit b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.git.commit new file mode 100644 index 0000000..109cacc --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.git.commit @@ -0,0 +1 @@ +866186c16e42c72886f5529feb1de754cdb93d54 \ No newline at end of file diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.name b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.name new file mode 100644 index 0000000..cced201 --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.name @@ -0,0 +1 @@ +lab8-mlflow.py \ No newline at end of file diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.type b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.type new file mode 100644 index 0000000..0c2c1fe --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.source.type @@ -0,0 +1 @@ +LOCAL \ No newline at end of file diff --git a/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.user b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.user new file mode 100644 index 0000000..710cb86 --- /dev/null +++ b/mlruns/0/8e73be609cf045c9a792e9712a5482d6/tags/mlflow.user @@ -0,0 +1 @@ +przemek \ No newline at end of file diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/meta.yaml b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/meta.yaml new file mode 100644 index 0000000..0c580a8 --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/meta.yaml @@ -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 diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/metrics/rmse b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/metrics/rmse new file mode 100644 index 0000000..93741b3 --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/metrics/rmse @@ -0,0 +1 @@ +1621078798313 0.09201313 0 diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/Last loss b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/Last loss new file mode 100644 index 0000000..70d276b --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/Last loss @@ -0,0 +1 @@ +0.3280356824398041 \ No newline at end of file diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/batch size b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/batch size new file mode 100644 index 0000000..19c7bdb --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/batch size @@ -0,0 +1 @@ +16 \ No newline at end of file diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/epochs b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/epochs new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/params/epochs @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.git.commit b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.git.commit new file mode 100644 index 0000000..109cacc --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.git.commit @@ -0,0 +1 @@ +866186c16e42c72886f5529feb1de754cdb93d54 \ No newline at end of file diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.name b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.name new file mode 100644 index 0000000..cced201 --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.name @@ -0,0 +1 @@ +lab8-mlflow.py \ No newline at end of file diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.type b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.type new file mode 100644 index 0000000..0c2c1fe --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.source.type @@ -0,0 +1 @@ +LOCAL \ No newline at end of file diff --git a/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.user b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.user new file mode 100644 index 0000000..710cb86 --- /dev/null +++ b/mlruns/0/a5a700d065624643b0e7e7addd6ec479/tags/mlflow.user @@ -0,0 +1 @@ +przemek \ No newline at end of file diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/meta.yaml b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/meta.yaml new file mode 100644 index 0000000..3aca9fd --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/meta.yaml @@ -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 diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/metrics/rmse b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/metrics/rmse new file mode 100644 index 0000000..ba3e5ad --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/metrics/rmse @@ -0,0 +1 @@ +1621078791153 0.09705861 0 diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/Last loss b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/Last loss new file mode 100644 index 0000000..6ab9fba --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/Last loss @@ -0,0 +1 @@ +0.3212756812572479 \ No newline at end of file diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/batch size b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/batch size new file mode 100644 index 0000000..19c7bdb --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/batch size @@ -0,0 +1 @@ +16 \ No newline at end of file diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/epochs b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/epochs new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/params/epochs @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.git.commit b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.git.commit new file mode 100644 index 0000000..109cacc --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.git.commit @@ -0,0 +1 @@ +866186c16e42c72886f5529feb1de754cdb93d54 \ No newline at end of file diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.name b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.name new file mode 100644 index 0000000..cced201 --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.name @@ -0,0 +1 @@ +lab8-mlflow.py \ No newline at end of file diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.type b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.type new file mode 100644 index 0000000..0c2c1fe --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.source.type @@ -0,0 +1 @@ +LOCAL \ No newline at end of file diff --git a/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.user b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.user new file mode 100644 index 0000000..710cb86 --- /dev/null +++ b/mlruns/0/bb1356a5d8fd4a048612acedc090167f/tags/mlflow.user @@ -0,0 +1 @@ +przemek \ No newline at end of file diff --git a/mlruns/0/meta.yaml b/mlruns/0/meta.yaml new file mode 100644 index 0000000..5c1fdb5 --- /dev/null +++ b/mlruns/0/meta.yaml @@ -0,0 +1,4 @@ +artifact_location: file:///home/przemek/ium_434766/mlruns/0 +experiment_id: '0' +lifecycle_stage: active +name: Default diff --git a/stroke.pth b/stroke.pth index 573867c..705a206 100644 Binary files a/stroke.pth and b/stroke.pth differ