No-code Retraining

The Azure Machine Learning connector for Logic Apps enables the scheduling retraining of models without having to write any code.

# Use an Azure Logic App to Schedule Retraining Models #
Azure Logic Apps enable the calling of Azure Machine Learning APIs to perform the retraining of models for Classic Machine Learning web services.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/createlogicapp1.png)
For more information on Logic Apps, see [What are Logic Apps?](https://azure.microsoft.com/en-us/documentation/articles/app-service-logic-what-are-logic-apps/)
To retrain:
2. Deploy your training experiment as a Retraining Web service.
3. Add an endpoint to your predictive Web Service.
4. Deploy a Logic APP.
3. Update the Logic APP with the Batch Execution Service API URL and API Key for the retraining Web service from the [Azure Machine Learning Web Services](https://services.azureml.net) portal.
4. Update the Logic App with the with the information for the predictive Web service's added endpoint.
4. Run the Logic App.
For more information on retraining, see [Retrain Machine Learning models programmatically](https://azure.microsoft.com/en-us/documentation/articles/machine-learning-retrain-models-programmatically/).
## Create a Logic App for Retraining ##
Use the *Batch Job with Input and Output* and *Set Up Retraining* modules to set up scheduled retraining of your machine learning model.
The *Batch Job with Input and Output* module uses a retraining Web service to create an updated scoring model. The *Set Up Retraining* module updates the Predictive Web service with the new model.
You can create a Logic App to run the updated Predictive Web service using the updated endpoint. For more information, see [Use an Azure Logic App to Schedule Running Batch Jobs]().
### Prerequisites
Before you create your Retraining Logic App, you must:
* Deploy your Training Experiment as a Retraining Web service.
* Add an endpoint to your Predictive Web Service that can be retrained.
For more information on retraining, see [Retrain Machine Learning models programmatically](https://azure.microsoft.com/en-us/documentation/articles/machine-learning-retrain-models-programmatically/).
For information on adding an endpoint to a Machine Learning Web service, see [Creating Endpoints](https://azure.microsoft.com/en-us/documentation/articles/machine-learning-create-endpoint/).
### Deploy the Logic App
1. Sign in to the Azure portal ([https://portal.azure.com](https://portal.azure.com))
1. On the hub menu, click **New > Web+Mobile > Logic App**.
1. Enter a name for the Logic App.
2. Choose a subscription.
3. Choose a resource group.
4. Choose a location.
2. Click **Create**.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/createlogicapp2.png)
### Build the retraining Logic App ###
To retrain the model, you must create a job that calls the Batch Execution Service API to produce a new model based on the new data.
On the dashboard, select your logic app. You can search for it by clicking the **See More** at the bottom of **All Resources**. The Logic App Designer opens.
1. In the **Logic Apps Designer**, click **Blank LogicApp**.
1. In the list of triggers, click **Recurrence**.
1. Click **New Step**, then Add an Action.
1. In Search, type *Azure ML*.
1. Select **Azure ML - Batch Job with Input and Output**.
In the **Services** blade, select **Storage accounts.** If it is not visible, you can click **More services** and search for it. For the retraining logic flow, we are not going to specify the storage information. The Logic App will use the defaults which will be passed to the retraining module.
Select or create a storage account:
- Enter name in the Storage Account Name (Input).
- Enter the key in the Storage Account Key (Input).
- Enter container name in the Storage Container Name (Input) and Storage Container Name (Output) fields.
Next, you need the Web Service Batch Execution Service API URL and API Key.
1. Sign in to the [Azure Machine Learning Web Services](https://services.azureml.net) portal.
1. Click **Classic Web Services**.
2. Click your retraining Web service.
3. Click the default endpoint.
2. Click **Consume**.
3. From the Consume page, copy the **Primary Key** to the **API Key** field in the Logic App. Copy the **Batch Requests** URL to the **API POST URL** field.
4. Enter the name of the blob that contains the data for the input in **Blob Name (Input)**.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain1.png)
The completed module should look similar to the following:
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain2.png)
In addition, you can include Global (Web service) Parameters if your experiment includes them. For more information on Web service parameters, see [Use Azure Machine Learning Web Service Parameters](machine-learning-web-service-parameters.md).
To add Web service parameters, click **Show Advanced Options**.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/gp1.png)
In the Global Parameter fields, enter one or more global (Web service) parameters in a comma separated list of fields and values.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/gp2.png)
To add Web service parameters, click **Show Advanced Options**.
In the Global Parameter fields, enter one or more global (Web service) parameters in a comma separated list of fields and values.
### Add the Retraining module
1. Click **New Step**, then Add an Action.
1. In Search, type *Azure ML*.
1. Select **Azure ML - Set Up Retraining**.
The Retraining module allows you to receive the results from the previous module as input.
In the retraining module, click in **Retrained Results**, then click **Add dynamic content**.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain3.png)
The **Trained Model Output Name** is the name of the Web service module attached to the Trained Model module in your retraining experiment. Open your training experiment in Machine Learning Studio and click the Web service module. The name is in the properties pane to the right of the experiment canvas.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain4.png)
The Scoring Web service URL is the PATCH URL of the endpoint that you added to your Predictive Web service. You can obtain it from the [Machine Learning Web Services](http://services.azureml.net) portal.
1. Sign in to the [Azure Machine Learning Web Services](https://services.azureml.net) portal.
1. Click **Classic Web Services**.
2. Click your predictive Web service.
3. Click the added endpoint.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain5.png)
2. Click **Consume**.
3. From the Consume page, copy the **Primary Key** to **Scoring Web Service Key** in the Logic App. Copy the **Patch** URL to the **Scoring Web Service URL**.
![http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain6.png)
To get the Resource Name, click **API Help**. Find the **Updatable Resources** section and copy the **Resource Name** to **Resource Name** in the retraining module.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain7.png)
You can choose to update the Model every time or make the update contingent upon evaluating the new model. If you choose to update every time, leave **Evaluation Model Output Name**, **Evaluation Result Key**, **Evaluation Condition**, and **Evaluation Value blank**.
To make the model update conditional:
- In **Evaluation Model Output Name**, type the name of the Web service module that is connected to the Evaluate Model module.
- In **Evaluation Result Key**, type the name of the column that contains the result to be evaluated.
- In **Evaluation Condition**, type the condition to use in the evaluation. Valid values are: >, <, ==, =>, and =<.
- In **Evaluation Value**, type the desired threshold value for the Result Key to check against.
The resultant form should look similar to the following:
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain8.png)
Click Save and the Logic App runs. The Logic App runs two jobs, one that calls the Batch Execution Service and one that applies the retrained model to the predictive web service. On successful completion, you will see a success for both jobs.
![](http://az712634.vo.msecnd.net/tutorials/No-code-web-service-retraining/ncrt-nocoderetrain9.png)
## Summary ##
Using Azure Logic Apps, you can run retraining jobs that are executed on demand or on a recurring schedule.