DEV Community

Cover image for Training Machine Learning models in AzureML
Vivek0712
Vivek0712

Posted on

Training Machine Learning models in AzureML

Welcome to the next part of my blog series on Azure Machine Learning. Now we are going to jump into one of the most important aspect of the MLOps - Training of Machine Learning Models.

Usually Machine Learning models require high compute power to train on the dataset. It is quite evident that not everyone has access to high processing and storage capabilities. So, keeping in mind of the cost of procuring the infrastructure for the same, its better option to leverage the cloud resources and pay for the usage.

Now, coming to training of Machine Learning models in Azure, we are going to follow simple steps to do so. At the end of the article, you will have created a training environment, trained your ML model and stored the artefacts of the models for future use.

Steps

  1. Setup the environment
  2. Creating your ML Script
  3. Create Training Environment dependency file
  4. Training the model

Setup the Environment for ML

Follow the previous article to create Workspace, Compute and Data.

Creating your ML Script

Before creating the ML Script, lets first create the directories for source files

The ML Script does the following

  • Parsess the Argument passed to the script (Input Data and Hyperparameters)
  • Starts the run for the experiment
  • Does all the ML Training
  • Logs the metrics of the run
  • Stores the output model

Creating Training Environment Dependency File

An Environment is managed and versioned in an Azure Machine Learning Workspace. You can update an existing environment and retrieve a version to reuse. Environments are exclusive to the workspace they are created in and can't be used across different workspaces.

We will use YAML file to list the dependencies of the environment we are going to use

Training the Machine learning Model

  • Create the environment from the dependency file
  • Creating Configuration for Python Script
  • Submitting the Script to the Experiment
  • Register the model along with the RSME Value

We are going to create 10 different runs for 10 different Alpha values for our Ridge Algorithm to be trained on the Diabetes Dataset. The model with less RMSE will be considered as best model.

A ScriptRunConfig packages together the configuration information needed to submit a run in Azure ML, including the script, compute target, environment, and any distributed job-specific configs.

A model is the result of a Azure Machine learning training Run or some other model training process outside of Azure.Register a model with the provided workspace, we use register method.

We have successfully created and trained our Machine Learning model. In next article, we will see how to deploy our model to production and perform real-time inference.

Top comments (2)

Collapse
 
aatmaj profile image
Aatmaj

That is just awesome!

Collapse
 
vivek0712 profile image
Vivek0712

Thank you.