Skip to content

elenacramer/nd00333_AZMLND_C2

Repository files navigation

Training-Deploying-Consuming ML models using AzureML

In this project we will demonstrate an end-to-end ML example, that is, from model training to model deployment to consuming a model. Although we will train a model, our focus will be on deployment and consumption.

Data Set

The data set we will use her is the same as for the previous project, i.e. a collection of bank client information such as age, marital status, job, education ect. and the goal is to predict whether a client will subscribe to a term deposit or not, described by the variable "y".

Overview

Generally speaking, deploying a machine learning model simply means to integrate a machine learning model and integrate it into an existing production environment. Before we can deploy a model, we need a to train and save a model (also possible to regist it). Once we have a pre-trained model, we can deploy it as-is. This means that our deployed web service will take the same input data as our trained model and will output the prediction.

diagram

We will deploy a model in an ACI (Azure Container Instance). ACIs in Azure Machine Learning are meant to be used for development and testing purposes, as they only support low-scale workloads on CPUs. Yet, they can make use of up to 16GB of RAM and 4 CPUs. After deploying a model the web service will appear in the Azure Machine Learning portal, under the Endpoints section. There, we can obtain its REST endpoint’s URI which we use to interact with the model.

We deploy a model in two different ways. First we use Automated ML in the Azure ML platform and than we use the Python SDK to create a pipeline with AutoML steps. The apporaches have two things in common; both require loading the data set and both use AutoML to train and retrieve the best model.

Automated ML

The required steps for training, deploying and consuming a model using Automated ML:

  • Create a new Automated ML run & experiment
    • Configure a new compute cluster
      • Select Virtual Machine, the minimum and maximum number of nodes
    • Select best model for deployment
  • Deploy the best model
    • Enable Authentication and use Azure Container Instance (ACI)
    • Enable Application Insights:
      • Running the script logs.py enables to view the logs
  • Consume deployed model
    • Using Swagger
      • Download the swagger.json file (can be found under the Endpoint section -> deployed model)
      • Must be downloaded to the same directory as swagger.sh and serve.py
      • Run swagger.sh and sesrve.py
    • Using a deployed service via an HTTP API ( that is a URL that is exposed over the network so that interaction with a trained model can happen via HTTP requests)
      • Interact with the endpoint via running the script endpoint.py
        • To run the script the "scoring uri" and a "key" must be provided (generated by the deployed model)

Key Steps

  • Loaded data set dataset

  • Experiment is completed: experiment_completed

  • Models of the Automated ML run: models

  • Best model of the completed Automated ML run: best_model

  • Application insights is a useful tool to detect anomalies and visualize performance. Running the script logs.py provides informational output produced by the software, i.e. logs.

Here we can see that the application insights is enabled: app_insights and the logs: Logs

  • Swagger is a tool that helps build, document, and consume RESTful web services.swagger.sh runs the swagger UI container and makes it available on port 9000. After the Swagger UI container is running, we can access the website on http://localhost:9000. Running serve.py enables the contents of swagger.json to be consumed locally by Swagger. It will run and serve contents on localhost:8000. Here we can see Swagger running on localhost showing the HTTP API methods: swagger

  • We can interact with the endpoint using the script endpoint.py. It contains data about two clients we want to make a prediction on. By running the scripts we obtain the desired predictions: model_pred

Pipeline with AutoML Steps

The required steps using Python SDK and Pipeline object:

  • Crreate an experiment and attach an AmlCompute cluster
  • Train
    • Create AutoMLConfig object
  • Create a Pipeline
    • Load data set from datastore
    • Create AutoMLStep
    • Create Pipeline object
    • Submit experiment
    • Retrieve best model
  • Publish and run from REST endpoint

Key Steps

  • Pipeline is created: pipeline_created

  • Bankmarketing dataset with the AutoML module the “Published Pipeline overview”, showing a REST endpoint and a status of ACTIVE: pipeline_overview

  • Pipeline Endpoint from Pipeline section: pipeline_endpoint

  • Running steps using the RunDetails Widget in the notebbok: running_steps_notebook

  • Scheduled / completed run scheduled_run

Screen Recording

Screencast

Standout Suggestions

In the AutoML step, we set the featurization parameter of the AutoMLConfig class to 'auto', meaning that the featurization step should be done automatically. We can perhaps improve the model by using customized featurization by passing a FeaturizationConfig object to the featurization parameter of the AutoMLConfig class. This, for example, enables us to choose a particular encoder for the categorical variables, a strategy to impute missing values, ect..

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors