3838
3939# Add golden data set on which all the model performance can be evaluated
4040
41- # Get the latest run_id
41+ # Get the latest run_id
4242with open ("aml_config/run_id.json" ) as f :
4343 config = json .load (f )
4444
4545new_model_run_id = config ["run_id" ]
4646experiment_name = config ["experiment_name" ]
47- exp = Experiment (workspace = ws , name = experiment_name )
47+ exp = Experiment (workspace = ws , name = experiment_name )
4848
4949
5050try :
51- # Get most recently registered model, we assume that is the model in production. Download this model and compare it with the recently trained model by running test with same data set.
52- model_list = Model .list (ws )
53- production_model = next (filter (lambda x : x .created_time == max (model .created_time for model in model_list ), model_list ))
54- production_model_run_id = production_model .tags .get ('run_id' )
55- run_list = exp .get_runs ()
56- # production_model_run = next(filter(lambda x: x.id == production_model_run_id, run_list))
51+ # Get most recently registered model, we assume that is the model in production. Download this model and compare it with the recently trained model by running test with same data set.
52+ model_list = Model .list (ws )
53+ production_model = next (
54+ filter (
55+ lambda x : x .created_time == max (model .created_time for model in model_list ),
56+ model_list ,
57+ )
58+ )
59+ production_model_run_id = production_model .tags .get ("run_id" )
60+ run_list = exp .get_runs ()
61+ # production_model_run = next(filter(lambda x: x.id == production_model_run_id, run_list))
5762
63+ # Get the run history for both production model and newly trained model and compare mse
64+ production_model_run = Run (exp , run_id = production_model_run_id )
65+ new_model_run = Run (exp , run_id = new_model_run_id )
5866
59- # Get the run history for both production model and newly trained model and compare mse
60- production_model_run = Run ( exp , run_id = production_model_run_id )
61- new_model_run = Run ( exp , run_id = new_model_run_id )
62-
63- production_model_mse = production_model_run . get_metrics (). get ( 'mse' )
64- new_model_mse = new_model_run . get_metrics (). get ( 'mse' )
65- print ( 'Current Production model mse: {}, New trained model mse: {}' . format ( production_model_mse , new_model_mse ) )
67+ production_model_mse = production_model_run . get_metrics (). get ( " mse" )
68+ new_model_mse = new_model_run . get_metrics (). get ( "mse" )
69+ print (
70+ "Current Production model mse: {}, New trained model mse: {}" . format (
71+ production_model_mse , new_model_mse
72+ )
73+ )
6674
67- promote_new_model = False
68- if new_model_mse < production_model_mse :
69- promote_new_model = True
70- print (' New trained model performs better, thus it will be registered' )
75+ promote_new_model = False
76+ if new_model_mse < production_model_mse :
77+ promote_new_model = True
78+ print (" New trained model performs better, thus it will be registered" )
7179except :
72- promote_new_model = True
73- print (' This is the first model to be trained, thus nothing to evaluate for now' )
80+ promote_new_model = True
81+ print (" This is the first model to be trained, thus nothing to evaluate for now" )
7482
7583run_id = {}
76- run_id [' run_id' ] = ''
84+ run_id [" run_id" ] = ""
7785# Writing the run id to /aml_config/run_id.json
7886if promote_new_model :
79- run_id [' run_id' ] = new_model_run_id
87+ run_id [" run_id" ] = new_model_run_id
8088
81- run_id [' experiment_name' ] = experiment_name
82- with open (' aml_config/run_id.json' , 'w' ) as outfile :
83- json .dump (run_id ,outfile )
89+ run_id [" experiment_name" ] = experiment_name
90+ with open (" aml_config/run_id.json" , "w" ) as outfile :
91+ json .dump (run_id , outfile )
0 commit comments