66from sklearn .metrics import confusion_matrix , accuracy_score
77from sklearn .model_selection import cross_val_score
88from 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
1017DATA_PATH = os .path .abspath (sys .argv [1 ])
1118CRED_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 ("\n Extracting 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
0 commit comments