Azure ML service is an end-to-end machine learning service available on Azure which can help data scientist to automate the machine learning life-cycle. The model can be built in the local then deploy, train and validate it on the cloud. Azure ML Service currently supports Python SDK, .NET SDK and Java SDK. In this article, I use the Python for the development.
We explore how to train a machine learning model using the Azure ML service. Then, we talk about the purpose and role of experiments, runs, and models. Finally, We exercise how to train ML models with Azure resource available that includes creates a workspace, builds a compute target, and executes a training run using the Azure ML service.
1) Create a workspace
Workspace is where all references of ML resources are centralized. It keeps the historical logs of training, run versions. It allows us to define different Compute Targets to run your experiments where we pipeline the process of building ML model.
MS Azure offers us several ways to create a workspace. We can use either Azure Portal or Azure CLI or REST Service or Resource Template. I highly recommend to use Azure Portal because it is easy just with some clicks.
The first condition is to have a valid account and a valid subscription. Check out this article to see how to get one.
Check out this part to get step by step of workspace creation
Once we sucessfully created a workspace for Machine Learning, we should see it on our home page.
My workspace name is diemai_workspace:
Click on the workspace name to get the details.
My workspace's resource group is cognitiveai which is a subscription name and it is free in 30 days.
My workspace's resource group is cognitiveai which is a subscription name and it is free in 30 days.
2) Create and train Machine Learning model with Azure ML Service
First, we have to create an instance of workspace with Python by using azureml.core.Workspace object and filling the parameters with workspace name, subscription ID and group name as the following:
3) Setup the computing resources
We need to specify a compute configuration that specifies virtual computer target and virtual machine type and size used in the computation. I set the computer target is amlcompute and its type is Standard_F2s_v2. I also indicate the version of python packages that are used in the run.
The reason I set Standard_F2s_v2 for vm_size because it is valid resources provided by Azure when we created a subscription. vm_size is changed when we change the region of subscription. To know which resources are available for use, run the following command:
AmlCompute.supported_vmsizes(workspace = diemai_ws)
4) Create a python script with selected dataset and ML Algorithm
After running the above code, we got a python file lg_house_boston.py in the local directory. We continue to execute that file and finally, we got trainset and testset variables as well as an instance of Linear Regression saved in lg_house_boston.pkl file.
5) Run Script
Now, we create a Run Script where we specify the python script and computing resource:
6) Experiment and Task Submit
Last step is to setup an experiment and submit it to Azure Cloud
7) Download model to the local
We can download running model on Cloud to local and validate it with testset and compute mean square error
No comments:
Post a Comment