Select Page

Data Engineering and MLOps specialist: Streamlining EDW & Data Pipelines for ML & AI products.

Azure ML studio provides 3 artifacts for conducting machine learning experiments.

  1. Notebooks
  2. Automated ML
  3. Designer

In this article, we will see how we can use notebooks to build a machine learning experiment.

From Azure ML studio, Click on Start now button on the Notebooks (or, alternatively, click on create new -> Notebook)

I have created a new folder TestModel, and a file called main.py from the interface above.

Structure of Azure Experiment:

It’s important to understand the structure of an experiment in azure and the components involved in successfully executing one.

Workspace:

Azure Machine Learning Workspace is the environment which provides all the resources required to run an experiment. For example, if we were to create a word document, then Microsoft Word in this example would be equivalent to a workspace as it provides all the resources.

Experiment:

An Experiment is a group of Runs ( actual instances of experiments). To create a machine learning model, we may have to create experiment runs multiple times. What groups the individual runs together is an experiment.

Run:

A run is an individual instance of an experiment. A run is one single execution of code. We use run to capture output, analyze results and visualize metrics. If we have 5 runs in an experiment. We can compare the same metrics for 5 runs in one experiment to evaluate the best run and work towards anoptimum model.

Environment:

The environment is another important concept in Azure Machine learning. It defines

  1. Python packages
  2. Environment variables
  3. Docker settings

An Environment is exclusive to the workspace it is created in and cannot be used across different workspaces.

Types of environments:

There are 3 types of environments supported in Azure Machine Learning.

  1. Curated: Provided by Azure, intended to be used as-is. Helpful in getting started.
  2. User-Managed: We( set up the environment and install packages that are required on compute target.
  3. System-Managed: Used when we want Conda to manage Python environment and script dependencies.

We can look at curated and system-managed environments from the environment link in Azure ML Studio.

To create an experiment, we use a control script. The control script decides workspace, experiment, run and some other configuration required to run an experiment.

Creating Control Script

A control script is used to control how and where your machine learning code is run.

from azureml.core import Workspace, Experiment, Environment, ScriptRunConfig

ws = Workspace.from_config()

experiment = Experiment(workspace=ws,name="python-test")

config = ScriptRunConfig(source_directory='./', script='main.py', compute_target="Test-Compute-Manan")

run = experiment.submit(config)

am_url= run.get_portal_url()

print(am_url)
Step Code Function
1 ws = Workspace.from_config() Connects to Azure Machine Learning workspace to access all ML resources
2 experiment = Experiment(workspace=ws,name=”python-test”) Experiment class provides a way to organize multiple runs under a single name.
3 config = ScriptRunConfig( This function is used to configure how we want our compute to run our script in Azure Machine Learning Workspace
4 run = experiment.submit(config) This function submits a run. A run is a single execution of your code.
5 am_url= run.get_portal_url()

 

Running the Experiment

Our control script is now capable of instructing Azure Machine Learning workspace to run our experiment from the main.py file.  Azure ML studio automatically takes care of creating experiments and run entries in the workspace we specified. To confirm what our code did, we can head back to our Azure ML workspace. It created an Experiment and a run. Azure automatically creates a fancy display name for a run which in our case is strong malanga. My first few runs failed because of some configuration errors. Running it for 3rd time marks a successful run for the experiment python-test.