How to install and use the Azure Machine Learning Python SDK

How to install and use the Azure Machine Learning Python SDK


>>Hello, my name’s Haining. I’m a program manager on
Azure Machine Learning Team. Today, I’m going to show
you how to get started with Azure Machine Learning
SDK in Python. The first thing I need
to do is to create an isolated Python environment. For that, I choose
to use Miniconda. So, in my search engine, I will type “Install Miniconda”, and this will lead me to
the “Conda installer” page. Now, I’m using Mac and I’ve
already installed Miniconda. But make sure you choose the proper installer for
your operating system. Once the Miniconda is installed, come back to
your command line and then type “Conda create-n”. Choose a name for
your environment, in this case, I’m using “Myenv” and
choose Python 3.6. Go ahead, and now the Conda is going to create
a Python environment for me, and this is where we’re
going to install SDK. It looks like the
environment is ready and next thing to do
is to activate it. So, I’m going to say,
“Conda Activate Myenv”. Once the environment
is activated, I’m ready to install the SDK. So, I will type “Pip
install Azureml-SDK”. Normally, if I were to just use the basic SDK that
will be sufficient, but in this case I
will also include some of the components that are
designed for Jupyter Notebook. So, I will say, square
bracket, notebooks, and hit “Enter” and this will start
the Pip Install process. Okay, it looks like
the installation succeeded. Now, I’m ready to launch
Jupyter Notebook. Notice that the
Notebook is actually installed as part of
the Pip Install package. Now, I’m in an empty
directory here, so, I’m going to create
a new Notebook, and this will be using
the Python 3 Kernel, which is the Python
3.6 environment. I’m going to change
the Notebook name to AzureML SDK Get Started. Now, the first thing
I need to do, is to ensure that I have
properly installed ML SDK. So, to do that, I will type importazureml.core and then I will print azureml.core.VERSION. So, this gives me
the version number of the SDK. Okay. The next thing to do, is to create a new workspace. So, I’m going to import workspace from
azureml.core as well. Then I will use the workspace.createAPI to
create a new workspace. Now, you can see this
API takes a number of parameters but effectively, you will need access to
a Azure subscription. So, you’re going to
say name equals to, in this case I’m using Hai
and also subscription ID. This is a grid representing
your Azure subscription. So, I’m going to copy
and paste it here. I’m going to start multiple lines so that
makes it easier to see. So, subscription ID, and then, I will need also
a resource group. So, I’m going to type
resource group name equals to, I’m going to actually create a new resource group,
it’s called “amlrg01”. Since this is a new
resource group, I will tell SDK to make sure
you go ahead and create one. So, create_resource_group,
and also by the way, I want this work space to be created in Azure region
called “EastUS2”, which is one of
the supported regions by Azure Machine Learning. So, I’ll hit “Shift Enter”. It looks like I mistyped
the parameter name, it’s just Resource Group. Alright, so, let’s try again. Now, once I hit shift to enter it launched
a new browser window, asked me to log in
to my Azure account. So, I’m just going to click on this name because I already
have my Azure ID cached. So, I click on it, and
then login succeeded, and I can see that it’s printed out that I have
already logged in. Now, it is looking for all subscriptions that
I have access to. Once that’s done, it’s
now going to go ahead and create the resource group because that group does not exist yet. So, it’s going to create
a new resource group in the EastUS2 region. Once that resource
group is created, it’s going to go ahead
and create the workspace, which also includes
a new storage account, a new Azure Container Registry, as well as an Azure [CROSSTALK] API to simply load the workspace. Okay, it looks like
the work space is properly created and
we can see this. We verify this by typing using the “Get Details”
API for workspace. You can see all the detailed information about the workspace. The one nice thing
about this SDK, is that you can actually
persist the work space details, or some of the work space
information on disk in a local file by using the ride.config folder
or ride.config SDK. Now, you can take a look at
these config adjacent file that’s created under
the AML_config folder. As you can see, this file
simply has subscription ID, resource group, and
work space name. Those are the three pieces
of information to uniquely identify
a work space. Now, next time, you can simply
use the from_config API to load the JSON file which will then instantiate
the workspace object. Now, the work space is created. At this point, you’re ready
to go with Azure ML SDK. I’m going to show you
a very simple example of leveraging the experiment log
in API’s in Azure ML SDK. So, I’m going to say from
azureml.core import experiment, and I’m going to create
a new experiment object, and it’s going to take
a work space object and a name. I’m just going to say, “Myexp”, that’s the name of
the experiment. Once I’ve created an experiment, then I can create any raw object, by calling the start
login API under experiment. Once the Rom is created, I can then simply
log anything I want. In this case, for example, I’m going to log a magic number, which of course is 42. I can also log a list
of numerical values. So, I’m going to just
call it a “My List”, and I will use some new
random numbers here, some small integers for example. That should be enough and then I will call
that rung complete. Of course, if this is a real
Machine Learning experiment, you can log any
metrics you want in between the rung start
and the rung complete. Now, let’s take
a look at this rung and just simply type
“Rung” and this will give me a link that will take me to
the Azure portal. I can look at the metrics that
I’ve logged for this rung. As you can see, this
is my experiment rung. I’ve logged to the “My List” as a list of
numerical values, so, it actually automatically
create a graph for me. Also, if you scroll down, you will see my magic number
is of course 42. Now, before we finish, I will highly recommend that you clone this GitHub repository, which includes
many advanced examples of using Azure Machine
Learning Python SDK. From training
a Deep Neural Network, to Hyper Parameter tuning, to deploy models in
a skill or fashion. Thank you for watching this video

Be the first to comment

Leave a Reply

Your email address will not be published.


*