Search code examples
azure-machine-learning-service

Code for Best Run and Model from previous experiment


For the best run and fitted model from a previously run experiment, Looking for the python code.


Solution

  • Below is the code you can reuse https://github.com/microsoft/MLOpsPython/blob/master/diabetes_regression/evaluate/evaluate_model.py

    Assuming in each previous experiment run, a model was registered with a tag that contains a metric of interest (test_mae for example), below is the code to retrieve the version with lowest mae.

    from azureml.core.model import Model
    
    model_name = "YOUR_MODEL_NAME"
    model_path = "LOCAL_PATH”
    model_version_list = [(model.version,float(model.tags["test_mae"])) for model in Model.list(workspace = ws,name =model_name)]
    model_version_list.sort(key = lambda a: a[0])
    lowest_mae_version =model_version_list[0][0]
    print("best version is {} with mae at {}".format(lowest_mae_version,model_version_list[0][1]))
    model = Model(name = model_name,workspace = ws, version =lowest_mae_version)
    model.download(model_path, exist_ok=True)
    

    when the model has not been registered,models in an automl run and would like to get all the models and compare the results depending on featurization, method used, and metrics, also with other data sets. The models are all inside the workspace with the GUI you can see them and download them by hand.