diff --git a/DEATH_EVENT.pth b/DEATH_EVENT.pth index 98e7250..2ce2b69 100644 Binary files a/DEATH_EVENT.pth and b/DEATH_EVENT.pth differ diff --git a/IUM_08_mlflow.py b/IUM_08_mlflow.py new file mode 100644 index 0000000..e816b8e --- /dev/null +++ b/IUM_08_mlflow.py @@ -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) diff --git a/MLproject b/MLproject new file mode 100644 index 0000000..0e66c2a --- /dev/null +++ b/MLproject @@ -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}" \ No newline at end of file diff --git a/__pycache__/IUM_08_mlflow.cpython-36.pyc b/__pycache__/IUM_08_mlflow.cpython-36.pyc new file mode 100644 index 0000000..4eda6ee Binary files /dev/null and b/__pycache__/IUM_08_mlflow.cpython-36.pyc differ diff --git a/fileObserver.py b/fileObserver.py index dfc0fcf..5f5b264 100644 --- a/fileObserver.py +++ b/fileObserver.py @@ -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 diff --git a/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/meta.yaml b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/meta.yaml new file mode 100644 index 0000000..0351e34 --- /dev/null +++ b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/meta.yaml @@ -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 diff --git a/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/metrics/accuracy_score b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/metrics/accuracy_score new file mode 100644 index 0000000..f8d5c9b --- /dev/null +++ b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/metrics/accuracy_score @@ -0,0 +1 @@ +1621170671205 0.55 0 diff --git a/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.git.commit b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.git.commit new file mode 100644 index 0000000..bf6b4e5 --- /dev/null +++ b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.git.commit @@ -0,0 +1 @@ +8e853f42dcd05f226e6f42086c9778fc3c9adcbf \ No newline at end of file diff --git a/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.name b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.name new file mode 100644 index 0000000..f94cdbd --- /dev/null +++ b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.name @@ -0,0 +1 @@ +IUM_08_mlflow.py \ No newline at end of file diff --git a/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.type b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.type new file mode 100644 index 0000000..0c2c1fe --- /dev/null +++ b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.source.type @@ -0,0 +1 @@ +LOCAL \ No newline at end of file diff --git a/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.user b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.user new file mode 100644 index 0000000..7decaf0 --- /dev/null +++ b/mlruns/0/9031aa80d3b948fca55268f6f0b0c117/tags/mlflow.user @@ -0,0 +1 @@ +naapster \ No newline at end of file diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/meta.yaml b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/meta.yaml new file mode 100644 index 0000000..3912f8c --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/meta.yaml @@ -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 diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/metrics/accuracy_score b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/metrics/accuracy_score new file mode 100644 index 0000000..712267c --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/metrics/accuracy_score @@ -0,0 +1 @@ +1621171451102 0.55 0 diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/Last loss b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/Last loss new file mode 100644 index 0000000..bc7ffee --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/Last loss @@ -0,0 +1 @@ +27.758575439453125 \ No newline at end of file diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/batch size b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/batch size new file mode 100644 index 0000000..9a03714 --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/batch size @@ -0,0 +1 @@ +10 \ No newline at end of file diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/epochs b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/epochs new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/params/epochs @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.git.commit b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.git.commit new file mode 100644 index 0000000..bf6b4e5 --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.git.commit @@ -0,0 +1 @@ +8e853f42dcd05f226e6f42086c9778fc3c9adcbf \ No newline at end of file diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.name b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.name new file mode 100644 index 0000000..f94cdbd --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.name @@ -0,0 +1 @@ +IUM_08_mlflow.py \ No newline at end of file diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.type b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.type new file mode 100644 index 0000000..0c2c1fe --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.source.type @@ -0,0 +1 @@ +LOCAL \ No newline at end of file diff --git a/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.user b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.user new file mode 100644 index 0000000..7decaf0 --- /dev/null +++ b/mlruns/0/b5ca2a8b58714cbdb4203ff66b024557/tags/mlflow.user @@ -0,0 +1 @@ +naapster \ No newline at end of file diff --git a/mlruns/0/meta.yaml b/mlruns/0/meta.yaml new file mode 100644 index 0000000..a6879ce --- /dev/null +++ b/mlruns/0/meta.yaml @@ -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