Skip to content

Commit f88efbc

Browse files
committed
adding deployment id to metadata file
1 parent 4d639f5 commit f88efbc

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

metadata.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
project_name: Rain_aus
2-
project_version: v0.3
3-
model_type: scikit-learn_0.23
41
author: guipleite
52
datetime_creted: 29/03/2021_13:46:23:802394723
3+
deployment_uid: 5876f2ba-1e57-41a7-b452-430da96f5ac7
4+
model_type: scikit-learn_0.23
5+
model_uid: 9db8c7d8-bd1d-4c0a-92da-fad29f1747e3
6+
project_name: Rain_aus
7+
project_version: v0.3

src/scripts/Pipelines/model_deploy_pipeline.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
import joblib
66
from ibm_watson_machine_learning import APIClient
77

8+
"""
9+
Usage:
10+
python3 model_deploy_pipeline.py ./pickle_model ../path/to/project/ ../credentials.yaml
11+
12+
"""
13+
814
MODEL_PATH = os.path.abspath(sys.argv[1])
915
PROJ_PATH = os.path.abspath(sys.argv[2])
1016
CRED_PATH = os.path.abspath(sys.argv[3])
@@ -60,3 +66,11 @@
6066
artifact_uid=model_uid,
6167
meta_props=deployment_props,
6268
)
69+
70+
deployment_uid = client.deployments.get_uid(deployment)
71+
72+
metadata["model_uid"] = model_uid
73+
metadata["deployment_uid"] = deployment_uid
74+
75+
f = open(META_PATH, "w+")
76+
yaml.dump(metadata, f, allow_unicode=True)

src/scripts/Pipelines/model_deployed_validate_pipeline.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from sklearn.metrics import confusion_matrix, accuracy_score
77
from sklearn.model_selection import cross_val_score
88
from ibm_watson_machine_learning import APIClient
9+
from sklearn.model_selection import train_test_split
10+
11+
"""
12+
Usage:
13+
python3 model_deployed_validate_pipeline.py path/to/data.csv ../../credentials.yaml path/to/project/
14+
15+
"""
916

1017
DATA_PATH = os.path.abspath(sys.argv[1])
1118
CRED_PATH = os.path.abspath(sys.argv[2])
@@ -20,26 +27,42 @@ def main():
2027
except yaml.YAMLError as exc:
2128
print(exc)
2229

30+
with open(META_PATH) as stream:
31+
try:
32+
metadata = yaml.safe_load(stream)
33+
except yaml.YAMLError as exc:
34+
print(exc)
35+
2336
data = pd.read_csv(DATA_PATH)
2437

2538
X = data.iloc[:, :-1]
2639
y = data[data.columns[-1]]
40+
X_train, X_test, y_train, y_test = train_test_split(
41+
X, y, test_size=0.3, random_state=0
42+
)
2743

2844
wml_credentials = {"url": credentials["url"], "apikey": credentials["apikey"]}
2945

3046
client = APIClient(wml_credentials)
3147
client.spaces.list()
3248

3349
SPACE_ID = credentials["space_id"]
34-
DEPLOYMENT_UID = input("DEPLOYMENT UID: ")
3550

36-
client.set.default_space(SPACE_ID)
51+
if "deployment_uid" in metadata.keys():
52+
DEPLOYMENT_UID = metadata["deployment_uid"]
53+
print("\nExtracting DEPLOYMENT UID from metadata file\n")
3754

38-
# deployment_uid = client.deployments.get_uid(DEPLOYMENT_UID)
55+
else:
56+
DEPLOYMENT_UID = input("DEPLOYMENT UID: ")
57+
58+
client.set.default_space(SPACE_ID)
3959

4060
payload = {
4161
"input_data": [
42-
{"fields": X.columns.to_numpy().tolist(), "values": X.to_numpy().tolist()}
62+
{
63+
"fields": X.columns.to_numpy().tolist(),
64+
"values": X_test.to_numpy().tolist(),
65+
}
4366
]
4467
}
4568
result = client.deployments.score(DEPLOYMENT_UID, payload)
@@ -53,7 +76,7 @@ def comb_eval(y, y_pred):
5376

5477
return {"cm": cm, "acc": acc}
5578

56-
eval = comb_eval(y, y_pred_values)
79+
eval = comb_eval(y_test, y_pred_values)
5780
print(eval)
5881

5982
return eval

src/scripts/Pipelines/t

-26.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)