Azure Machine Learning Service — Run a Simple Experiment

栏目: IT技术 · 发布时间: 6年前

Azure Machine Learning Service — Run a Simple Experiment

Part 2: How to code an ML model and execute the experiments using Azure Machine Learning Service.

Abstract

In Part 1 of this series I mostly covered an overview and introduction about Azure Machine Learning (AML) Service, in that post I covered setup, configuration, and various OOB capabilities on the offering by this cloud-managed service. I also discussed AML Workspace, AML Experiment and AML service experiment’s dashboard in detail.

In this Part 2, I will discuss how we can create an independent experiment script to encapsulate the core implementation of an ML model on the cloud, i.e. by training and tracking through repetitive experiment run. Also, I will demonstrate how to set up a prerequisite environment and configurations required to execute an experiment script.

This particular post is extracted from the Kaggle notebook hosted — here . Use the link to setup and execute the experiment

Azure Machine Learning Service — Run a Simple Experiment

Machine Learning Experiment Script

Once connected to the Azure Machine Learning workspace, the next step is to define a model experiment script, this is a very general python script which is loaded and executed form the experiment’s ‘workspace’ compute context. This also requires that the data files’ root (folder) has to be at the same location where this script is loaded, as shown below —

Azure Machine Learning Service — Run a Simple Experiment

Fig 1: Snapshot of Experiment Script — it’s mandatory to import azureml.core.Run class and execute its get_context() method

Experiment Output Folder —Mostly, Run of an experiment generates some output files, e.g. a saved model, that are saved in the workspace’s outputs folder as shown below —

os.makedirs("outputs", exist_ok=True)
joblib.dump(value=model, filename='outputs/iris_simple_model.pkl')
# Complete the run
run.complete()

One can also use the Run object’s upload_file method in the experiment file code as shown below, this enables that any files written to the outputs folder in the compute context are automatically uploaded to the run’s outputs folder when the run completed, e.g. —

run.upload_file(name='outputs/IRIS.csv', path_or_stream='./sample.csv') # upload from local

Run the Experiment

RunConfiguration and ScriptRunConfig

After the script for implementing the ML model is ready, the next step is to define RunConfiguration object — which defines the Python environment in which the script will run, and ScriptRunConfig object which associates the run environment with the script. The below code snippet instantiates the Python environment by calling the RunConfiguration() method and ScriptRunConfig() encapsulate the same environment for the script’s execution:

from azureml.core import Experiment, RunConfiguration, ScriptRunConfig# create a new RunConfig object
experiment_run_config = RunConfiguration()
experiment_run_config.environment.python.user_managed_dependencies = True
# Create a script config
src = ScriptRunConfig(source_directory=experiment_folder,
script='iris_simple_experiment.py',
run_config=experiment_run_config)

The RunConfig object also allows to additionally include the Python packages which are necessary for script execution.

Dashboard Results

Access the Azure Machine Learning Studio to navigate for the sample experiment run and verify the results in results on the dashboard. Here, the entire details of the experiment’s run history is displayed, as shown below — the details of run stats, history, results, metrics, logs, outputs, errors, diagnostics, etc.. are readily available from the dashboard:

Azure Machine Learning Service — Run a Simple Experiment

Fig 2: Dashboard results view for Iris-sample-experiment, observe the run stats and other metrics available.

Azure Machine Learning Service — Run a Simple Experiment

Fig 3: More detailed results are also available for any selected experiment, e.g. Run# 20

Azure Machine Learning Service — Run a Simple Experiment

Fig 4: Outputs folder has a model file uploaded by using the experiment’s script

Conclusion

In this part of the series, I tried to cover the most fundamental concept of Azure Machine Learning Service, i.e., to prepare and execute a machine learning experiment and generate a model binary. In the next article, I will cover a slightly more advanced way to set up and control the script’s execution environment, install or update the required dependencies & packages. So please stay tuned!

References

[1] Notebook & Code — Azure Machine Learning — Introduction , Kaggle.

[2] Azure Machine Learning Service Official Documentation, Microsoft Azure.


以上所述就是小编给大家介绍的《Azure Machine Learning Service — Run a Simple Experiment》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

代码之美

代码之美

Grey Wilson / 聂雪军 / 机械工业出版社 / 2008年09月 / 99.00元

《代码之美》介绍了人类在一个奋斗领域中的创造性和灵活性:计算机系统的开发领域。在每章中的漂亮代码都是来自独特解决方案的发现,而这种发现是来源于作者超越既定边界的远见卓识,并且识别出被多数人忽视的需求以及找出令人叹为观止的问题解决方案。 《代码之美》33章,有38位作者,每位作者贡献一章。每位作者都将自己心目中对于“美丽的代码”的认识浓缩在一章当中,张力十足。38位大牛,每个人对代码之美都有自......一起来看看 《代码之美》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具