In this project, I train a model based on the Bank Marketing dataset 1 data using AutoML in Azure ML Studio. The best performing model is determined by AutoML. Next, it is deployed for public consumption using an Azure Container Instance. We explore this using ML studio below, while the video delves into additionally using using the Python SDK pipeline in Step 8. Documentation.
Step 1. Authentication If operating on a personal machine, you'd create a Service Principal account and associate it with your specific workspace. In my case I did not, which is why it's omitted from the above diagram.
Step 2. Create/Run Automated ML Experiment
After Uploading source dataset, you're able to find and select it under Registered Datasets
- Created compute cluster using
Standard_DS12_v2VM with 1 minimum node. - Configured Task type and settings for AutoML run:
- Ensured Explain best model was selected
- Made the Training time(hours) to 1.
- Made sure Max Concurrency was set to 5.
- Changed primary metric from
AccuracytoAUC_weighteddue to highly imbalanced data.2 - Used Monte Carlo cross validation to validate data.
Once run is completed (see below), you'll see this screen:
The best performing model is shown below:
Notes early into the experiments run, run #7 with MaxAbsScaler, LightGBM model offered best performance; it wasn't until Run 40 that another combination (StandardScalerWrapper, XGBoostClassifier) edged out that earliy run by a mere .0027 difference in their AUC weighted.
Step 3 Deploy model
- Looking at Best Model in the Details tab shows us what our best model is.
- We will then deploy that model and enable "Authentication."
- Deploying the model enables it to interact with the HTTP API service as well as allowing users to interact with the model itself sending POST requests
- Our model is deployed using an Azure Container Instance (ACI)
Once the above is done, this message shows:
Step 4 Enable Logging
- We will use Python to enable Application Insights/logs (see
logs.pyscript) - By enabling Application Insights we're able to retrieve logs, which help detect performance anomalies and show error conditions as they happen; it also includes analytics tools.
We enable Application Insights so that the endpoints > voting-model screen shows this:
If we wait some time and then run logs.py again we can see the logs output:
Step 5 Swagger Documentation
It the details section we're able to find the Swagger URL, a link to a JSON file Azure provides are our deployed model.
That link is to our
swagger.json file; which contains details about our deployment.
It is saved as a file in the same directory as two others.
First, there's serve.py which will run a Python server on port 8000; then, we run bash and execute swagger.sh to download the latest Swagger container and then run it on port 9000.
The GET method allows us to retrieve data from a web server; the POST method requests that a web server accepts data enclosed in the body our message.
Once the above is done, navigating to localhost:9000 will show Swagger's UI - after typing in the correct web address, "http://localhost:9000/swagger.json", this provides documentation of the HTTP API methods/responses for the model.
You can look at the expected input payload for executing the real-time machine learning service.
And here are the HTTP API responses
Step 6 Consume Model Endpoint In the consume tab of Endpoints, under Basic consumption info, we're able to find two things we need for the next step:
Using endpoint.py we're able to issue a POST request to the deployed model.
This provides JSON output from the model:
Step 7 Create, Publish, and Consume Pipeline
We now switch over to a Jupyter notebook. We make sure our config.json file is available in the same directory as our file.
Then we set up our history container by setting some variables.
After setting a number of other variables for our compute cluster, etc., we're able to begin running our pipeline.
The Run Types of our experiments now show our Pipeline:
When you open up the experiment, it shows the latest run and Pipeline run overview as well as other details.
After completing pipeline run from Jupyter, it gives this message:
This is what it looks like when AutoML module completes.
You can see below that in Published Pipeline overview there's an active REST end point.
Here we can see that it is active:
The Run Details Widget shows steps:
Further, we can see scheduled/completed run here:
Step 8 Documentation
You can find the screen recording in the folder "screen_recording"
For your convenience, I've also put it on an unlisted Youtube link, available here: https://youtu.be/GRu8T03Hees
A second one which briefly goes into the notebook is also here (in case I wasn't in depth enough above): https://youtu.be/WBEaxd9o1ao
There are things we can do for imbalanced datasets that would have to come before the AutoML steps, according to Microsoft's own docs 3 1.Resampling to even the class imbalance, either by up-sampling the smaller classes or down-sampling the larger classes. These methods require expertise to process and analyze. 2. Review performance metrics for imbalanced data, particularly the F1 score. Exploring the precision (where higher = more false positives) and recall (where higher = fewer false negatives)
So these would be some things which would contribute to the success of future work using this data.
Other ideas would be letting the training process exceed an hour.
I would be interested in trying to train a similar classification model that is more balanced and comparing results as well.
I did hard-code cross-validation based on an example online - I would also be interested in running again and letting AutoML choose. In my experience, hard-coded happened to work slightly better, but I also tweaked a number of other things. So a systematic comparison of that step would also be interesting.
-
The data relates to direct marketing campaigns of a Portugese banking institution based on phone calls. The output variable is "y," which is a binary feature designating whether a person subscribed to a term deposit. Click here for more on the data source.
-
The data is imbalanced, so we have to change the data's primary metric from
Accuracy. See my first project's README for more on this issue. -
See the following from Azure ML Documentation for more on how to Manage ML pitfalls.
