Notebooks
A
Azure
Explain Model On Amlcompute

Explain Model On Amlcompute

how-to-use-azuremlazure-mldata-sciencenotebookexplain-modelmachine-learningremote-explanationazure-machine-learningdeep-learningazuremlazure-ml-notebooksazureazure-integration

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License.

Impressions

Train and explain models remotely via Azure Machine Learning Compute

This notebook showcases how to use the Azure Machine Learning Interpretability SDK to train and explain a regression model remotely on an Azure Machine Learning Compute Target (AMLCompute).

Table of Contents

  1. Introduction
  2. Setup
    1. Initialize a Workspace
    2. Create an Experiment
    3. Introduction to AmlCompute
    4. Submit an AmlCompute run
  3. Additional operations to perform on AmlCompute
  4. Download model explanations from Azure Machine Learning Run History
  5. Visualize explanations
  6. Next steps

Introduction

This notebook showcases how to train and explain a regression model remotely via Azure Machine Learning Compute (AMLCompute), and download the calculated explanations locally for visualization. It demonstrates the API calls that you need to make to submit a run for training and explaining a model to AMLCompute, download the compute explanations remotely, and visualizing the global and local explanations via a visualization dashboard that provides an interactive way of discovering patterns in model predictions and downloaded explanations.

We will showcase one of the tabular data explainers: TabularExplainer (SHAP).

Problem: Housing Price Prediction with scikit-learn (train a model and run an explainer remotely via AMLCompute, and download and visualize the remotely-calculated explanations.)

explanations-run-history

Setup

If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, make sure you go through the configuration notebook first if you haven't.

If you are using Jupyter notebooks, the extensions should be installed automatically with the package. If you are using Jupyter Labs run the following command:

	(myenv) $ jupyter labextension install @jupyter-widgets/jupyterlab-manager

[ ]

Initialize a Workspace

Initialize a workspace object from persisted configuration

[ ]

Create An Experiment

Experiment is a logical container in an Azure ML Workspace. It hosts run records which can include run metrics and output artifacts from your experiments.

[ ]

Introduction to AmlCompute

Azure Machine Learning Compute is managed compute infrastructure that allows the user to easily create single to multi-node compute of the appropriate VM Family. It is created within your workspace region and is a resource that can be used by other users in your workspace. It autoscales by default to the max_nodes, when a job is submitted, and executes in a containerized environment packaging the dependencies as specified by the user.

Since it is managed compute, job scheduling and cluster management are handled internally by Azure Machine Learning service.

For more information on Azure Machine Learning Compute, please read this article

If you are an existing BatchAI customer who is migrating to Azure Machine Learning, please read this article

Note: As with other Azure services, there are limits on certain resources (for eg. AmlCompute quota) associated with the Azure Machine Learning service. Please read this article on the default limits and how to request more quota.

The training script train_explain.py is already created for you. Let's have a look.

Submit an AmlCompute run

First lets check which VM families are available in your region. Azure is a regional service and some specialized SKUs (especially GPUs) are only available in certain regions. Since AmlCompute is created in the region of your workspace, we will use the supported_vms () function to see if the VM family we want to use ('STANDARD_D2_V2') is supported.

You can also pass a different region to check availability and then re-create your workspace in that region through the configuration notebook

[ ]

Create project directory

Create a directory that will contain all the necessary code from your local machine that you will need access to on the remote resource. This includes the training script, and any additional files your training script depends on

[ ]

Provision a compute target

Note that if you have an AzureML Data Scientist role, you will not have permission to create compute resources. Talk to your workspace or IT admin to create the compute targets described in this section, if they do not already exist.

You can provision an AmlCompute resource by simply defining two parameters thanks to smart defaults. By default it autoscales from 0 nodes and provisions dedicated VMs to run your job in a container. This is useful when you want to continously re-use the same target, debug it between jobs or simply share the resource with other users of your workspace.

  • vm_size: VM family of the nodes provisioned by AmlCompute. Simply choose from the supported_vmsizes() above
  • max_nodes: Maximum nodes to autoscale to while running a job on AmlCompute
[ ]

Configure & Run

[ ]

Note: if you need to cancel a run, you can follow these instructions.

[ ]
[ ]

Download

  1. Download model explanation data.
[ ]
[ ]
[ ]
[ ]
  1. Download model file.
[ ]
  1. Download test dataset.
[ ]
[ ]

Visualize

Load the visualization dashboard

[ ]
[ ]
[ ]