Quickstart Azureml In 10mins
![]()
Quickstart: Train and deploy a model in Azure Machine Learning in 10 minutes
In this quickstart, learn how to get started with Azure Machine Learning. You'll train an image classification model using the MNIST dataset.
You'll learn how to:
- Download a dataset and look at the data
- Train an image classification model and log metrics using MLflow
- Deploy the model to do real-time inference
Import Data
Before you train a model, you need to understand the data you're using to train it. In this section, learn how to:
- Download the MNIST dataset
- Display some sample images
You'll use Azure Open Datasets to get the raw MNIST data files. Azure Open Datasets are curated public datasets that you can use to add scenario-specific features to machine learning solutions for better models. Each dataset has a corresponding class, MNIST in this case, to retrieve the data in different ways.
Take a look at the data
Load the compressed files into numpy arrays. Then use matplotlib to plot 30 random images from the dataset with their labels above them.
Note this step requires a load_data function that's included in an utils.py file. This file is placed in the same folder as this notebook. The load_data function simply parses the compressed files into numpy arrays.
Train model and log metrics with MLflow
You'll train the model using the code below. Note that you are using MLflow autologging to track metrics and log model artefacts.
You'll be using the LogisticRegression classifier from the SciKit Learn framework to classify the data.
Note: The model training takes approximately 2 minutes to complete.
View Experiment
In the left-hand menu in Azure Machine Learning Studio, select Jobs and then select your experiment (azure-ml-in10-mins-tutorial). An experiment is a grouping of many runs from a specified script or piece of code. Information for the run is stored under that experiment. If the name doesn't exist when you submit an experiment, if you select your run you will see various tabs containing metrics, logs, explanations, etc.
Version control your models with the model registry
You can use model registration to store and version your models in your workspace. Registered models are identified by name and version. Each time you register a model with the same name as an existing one, the registry increments the version. The code below registers and versions the model you trained above. Once you have executed the code cell below you will be able to see the model in the registry by selecting Models in the left-hand menu in Azure Machine Learning Studio.
Deploy the model for real-time inference
In this section you learn how to deploy a model so that an application can consume (inference) the model over REST.
Create deployment configuration
The code cell gets a curated environment, which specifies all the dependencies required to host the model (for example, the packages like scikit-learn). Also, you create a deployment configuration, which specifies the amount of compute required to host the model. In this case, the compute will have 1CPU and 1GB memory.
Deploy model
This next code cell deploys the model to Azure Container Instance (ACI).
Note: The deployment takes approximately 3 minutes to complete.
The scoring script file referenced in the code above can be found in the same folder as this notebook, and has two functions:
- an
initfunction that executes once when the service starts - in this function you normally get the model from the registry and set global variables - a
run(data)function that executes each time a call is made to the service. In this function, you normally format the input data, run a prediction, and output the predicted result.
View Endpoint
Once the model has been successfully deployed, you can view the endpoint by navigating to Endpoints in the left-hand menu in Azure Machine Learning Studio. You will be able to see the state of the endpoint (healthy/unhealthy), logs, and consume (how applications can consume the model).
Test the model service
You can test the model by sending a raw HTTP request to test the web service.
Clean up resources
If you're not going to continue to use this model, delete the Model service using:
If you want to control cost further, stop the compute instance by selecting the "Stop compute" button next to the Compute dropdown. Then start the compute instance again the next time you need it.
Next Steps
In this quickstart, you learned how to run machine learning code in Azure Machine Learning.
Now that you have working code in a development environment, learn how to submit a job - ideally on a schedule or trigger (for example, arrival of new data).