1. Home
2. Training Library
3. Microsoft Azure
4. Courses
5. Using the Azure Machine Learning SDK

# Training a Model from a Datastore

1
4
7
20
22
26
29

## The course is part of this learning path

Start course
Overview
Difficulty
Intermediate
Duration
1h 23m
Students
691
Ratings
3.4/5
Description

Learn how to operate machine learning solutions at cloud scale using the Azure Machine Learning SDK. This course teaches you to leverage your existing knowledge of Python and machine learning to manage data ingestion, data preparation, model training, and model deployment in Microsoft Azure.

### Learning Objectives

• Create an Azure Machine Learning workspace using the SDK
• Run experiments and train models using the SDK
• Optimize and manage models using the SDK
• Deploy and consume models using the SDK

### Intended Audience

This course is designed for data scientists with existing knowledge of Python and machine learning frameworks, such as Scikit-Learn, PyTorch, and Tensorflow, who want to build and operate machine learning solutions in the cloud.

### Prerequisites

• Fundamental knowledge of Microsoft Azure
• Experience writing Python code to work with data using libraries such as Numpy, Pandas, and Matplotlib
• Understanding of data science, including how to prepare data and train machine learning models using common machine learning libraries, such as Scikit-Learn, PyTorch, or Tensorflow

### Resources

The GitHub repo for this course, containing the code and datasets used, can be found here: https://github.com/cloudacademy/using-the-azure-machine-learning-sdk

Transcript

When we uploaded the files earlier we noted that the code returned a reference. A reference provides a way to pass the path to a folder in a data store to a script regardless of where the script is being run so that the script can access data in the datastore location.

The code below gets a reference to the diabetes data folder where we upload the diabetes csv files. And what it does here is it specifically configures the data reference or download. So in other words, it can be used to download the contents of the folder to the compute context whenever the reference is being used.

Downloading data works well for small volumes of data that will be processed on a local computer but if we're working with remote compute we can also configure a little reference to monitor the store location and read data directly from the data store source.

To use the data reference in a trading script, we must define a parameter for it and we're going to run you know a few sort of instructions to get us to do that so first we need to set up a folder named "diabetes training" and after setting our folder we need a script that trains the classification model by using the training data and all the csv files in the folder reference by the data reference parameter passed to it.

Let's import the libraries we need to work with. So we need os, we need argparse to pass information to our script. We need run, we need pandas, we need numpy, we need joblib for pipelining and parallel parallelism. We need our train_test_split, we need LogisticRegression and we need metrics.

So here we use argparse to set up and get our parameters. And the parameters in question here as the regularization and then the data folder. Next, we get our run context. And then we load our data from a data reference. Next we separate features and labels, so we've got the following columns that are then stored in x and then we have feature, which is whether they are diabetic or not, stored in y are our target.

Next, we split the data into training and test sets and then we proceed to train our classification model. We pass on the regularization parameter we defined and then we run a prediction and log the results of the accuracy. We do the same for the area under the curve as well by invoking predict probability. And then the information governed from that, we pass that to our AUC score to calculate the necessary information and then log that.

Finally, we save our model and complete the run. The script will load the training data from the data reference passed to it as a parameter, so now we just need to set up the script parameters to pass the file reference when we run the experiment.

So to set up an experiment we import an SKLearn estimator. We have experiment class, we have run details, and then we set up our parameters that will be passed on into the script. Right, so here we're creating a specific estimator, SKLearn, and pass on the following parameters. So the source directory, we also have to supply the entry script which we've created earlier. Okay. And then the script parameters which we feed in the input we want to go into the script. And we specify our compute target which is local.

Okay. So let's create an experiment. It's called diabetes training and we pass that to, along with the workspace object, to experiment and then with experiment object. We then run experiment and set it up in such a way that it shows the run details whilst it's running. You can see some of the output of the run below here.

Please note as before the first time the experiment is run, it may take some time to set up the Python environment. Subsequent runs will obviously be quicker. When the experiment has completed, in the widget, you can view the azure ml logs to verify that the files were downloaded before the experiment script was run.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8954902,"math_prob":0.7420512,"size":6023,"snap":"2021-31-2021-39","text_gpt3_token_len":1217,"char_repetition_ratio":0.13689981,"word_repetition_ratio":0.0088495575,"special_character_ratio":0.19276108,"punctuation_ratio":0.08928572,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9512057,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-23T18:37:19Z\",\"WARC-Record-ID\":\"<urn:uuid:be9d6905-5adb-4b92-92b3-8f563f2d2262>\",\"Content-Length\":\"428217\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:892238c4-3176-4d19-b408-23efa3d48b07>\",\"WARC-Concurrent-To\":\"<urn:uuid:53b4cdb0-8cb9-4dfd-afb3-d3d8ece5e05b>\",\"WARC-IP-Address\":\"13.249.38.35\",\"WARC-Target-URI\":\"https://cloudacademy.com/course/using-the-azure-machine-learning-sdk-1087/training-a-model-from-a-datastore/\",\"WARC-Payload-Digest\":\"sha1:YSMHK4WQYVPOXKDVRETQLWBXNUJ277MH\",\"WARC-Block-Digest\":\"sha1:B6EK6YHR2LHR6R5KRKLWFFOTJ7TEXBBB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057427.71_warc_CC-MAIN-20210923165408-20210923195408-00107.warc.gz\"}"}