Defining an Environment
Start course
1h 23m

Learn how to operate machine learning solutions at cloud scale using the Azure Machine Learning SDK. This course teaches you to leverage your existing knowledge of Python and machine learning to manage data ingestion, data preparation, model training, and model deployment in Microsoft Azure.

If you have any feedback related to this course, please contact us at

Learning Objectives

  • Create an Azure Machine Learning workspace using the SDK
  • Run experiments and train models using the SDK
  • Optimize and manage models using the SDK
  • Deploy and consume models using the SDK

Intended Audience

This course is designed for data scientists with existing knowledge of Python and machine learning frameworks, such as Scikit-Learn, PyTorch, and Tensorflow, who want to build and operate machine learning solutions in the cloud.


  • Fundamental knowledge of Microsoft Azure
  • Experience writing Python code to work with data using libraries such as Numpy, Pandas, and Matplotlib
  • Understanding of data science, including how to prepare data and train machine learning models using common machine learning libraries, such as Scikit-Learn, PyTorch, or Tensorflow


The GitHub repo for this course, containing the code and datasets used, can be found here: 


When we run a Python script as an experiment in Azure machine learning, a core environment is created to define execution context for the script. Azure machine learning provides a default environment that includes many common packages, including the Azure ML defaults package, that contains the libraries necessary for working with an experiment run, as well as popular packages like Pandas and NumPy.

You can also define your own environment and outer packages by using Conda or PIP, to ensure your experiment has access to all the libraries it requires.

The following code creates an environment for the diabetes experiment. And we import the necessary classes, environment and Conda dependencies. We create a Python environment for the experiment. So, by setting user-managed dependencies to false, what it does is it lets Azure ML manage dependencies. We also have docker enabled, so, we can use a docker container.

We then create a set of package dependencies, Conda or PIP, as required, and then we add the dependencies to the environment. So now, we can use the environment for the experiment by sending it to an estimator, or we can assign it to run config. So, here the code assigns environment we've created with generic estimator, and submits an experiment.

As the experiment runs, we can observe the run details in the widgets, and we can also, have a look at the output logs, and see the Conda environment being built.

So, for our estimator, we import estimator, I experiment and run details classes. We then set up our script parameters. We get the training dataset, and then we create a generic estimator. Notes, the parameters, so, source directory, inputs by passing our diabetes dataset, our script params, our compute is local, environment the definition, our diabetes environment we set up, and our entry script is a diabetes training script.

We then create our experiment, run experiments, and set it up to show the run details while it is running. So, the experiment successfully used the environment, which included all the packages it required. So, now what we can do is then register our environment in the workspace. And that's accomplished by looking the register function in our diabetes environment, and as specified in the workspace, we want it registered in.

About the Author

Kofi is a digital technology specialist in a variety of business applications. He stays up to date on business trends and technology and is an early adopter of powerful and creative ideas.
His experience covers a wide range of topics including data science, machine learning, deep learning, reinforcement learning, DevOps, software engineering, cloud computing, business & technology strategy, design & delivery of flipped/social learning experiences, blended learning curriculum design and delivery, and training consultancy.