Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
APPLIES TO: Machine Learning Studio (classic)
Azure Machine Learning
Important
Support for Machine Learning Studio (classic) will end on 31 August 2024. We recommend you transition to Azure Machine Learning by that date.
Beginning 1 December 2021, you will not be able to create new Machine Learning Studio (classic) resources. Through 31 August 2024, you can continue to use the existing Machine Learning Studio (classic) resources.
ML Studio (classic) documentation is being retired and may not be updated in the future.
Retraining is one way to ensure machine learning models stay accurate and based on the most relevant data available. This article shows how to retrain and deploy a machine learning model as a new web service in Studio (classic). If you're looking to retrain a classic web service, view this how-to article.
This article assumes you already have a predictive web service deployed. If you don't already have a predictive web service, learn how to deploy a Studio (classic) web service here.
You'll follow these steps to retrain and deploy a machine learning new web service:
Note
We recommend that you use the Azure Az PowerShell module to interact with Azure. See Install Azure PowerShell to get started. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
A retraining web service lets you retrain your model with a new set of parameters, like new data, and save it for later. When you connect a Web Service Output to a Train Model, the training experiment outputs a new model for you to use.
Use the following steps to deploy a retraining web service:
Connect a Web Service Input module to your data input. Typically, you want to ensure that your input data is processed in the same way as your original training data.
Connect a Web Service Output module to the output of your Train Model.
If you have an Evaluate Model module, you can connect a Web Service Output module to output the evaluation results
Run your experiment.
After running your experiment, the resulting workflow should be similar to the following image:
Now, you deploy the training experiment as a retraining web service that outputs a trained model and model evaluation results.
At the bottom of the experiment canvas, click Set Up Web Service
Select Deploy Web Service [New]. The Machine Learning Web Services portal opens to the Deploy Web Service page.
Type a name for your web service and choose a payment plan.
Select Deploy.
For this example, we're using C# to create the retraining application. You can also use Python or R sample code to accomplish this task.
Use the following steps to call the retraining APIs:
Add the NuGet package Microsoft.AspNet.WebApi.Client, as specified in the comments. To add the reference to Microsoft.WindowsAzure.Storage.dll, you might need to install the client library for Azure Storage services.
The following screenshot shows the Consume page in the Machine Learning Web Services portal.
Locate the apikey declaration:
const string apiKey = "abc123"; // Replace this with the API key for the web service
In the Basic consumption info section of the Consume page, locate the primary key, and copy it to the apikey declaration.
The BES sample code uploads a file from a local drive (for example, "C:\temp\CensusInput.csv") to Azure Storage, processes it, and writes the results back to Azure Storage.
Locate the StorageAccountName, StorageAccountKey, and StorageContainerName declarations, and update the values that you saved from the portal.
const string StorageAccountName = "mystorageacct"; // Replace this with your Azure storage account name
const string StorageAccountKey = "a_storage_account_key"; // Replace this with your Azure Storage key
const string StorageContainerName = "mycontainer"; // Replace this with your Azure Storage container name
You also must ensure that the input file is available at the location that you specify in the code.
When you specify the output location in the Request Payload, the extension of the file that is specified in RelativeLocation must be specified as ilearner
.
Outputs = new Dictionary<string, AzureBlobDataReference>() {
{
"output1",
new AzureBlobDataReference()
{
ConnectionString = storageConnectionString,
RelativeLocation = string.Format("{0}/output1results.ilearner", StorageContainerName) /*Replace this with the location you want to use for your output file and a valid file extension (usually .csv for scoring results or .ilearner for trained models)*/
}
},
Here is an example of retraining output:
When you run the application, the output includes the URL and shared access signatures token that are necessary to access the evaluation results.
You can see the performance results of the retrained model by combining the BaseLocation, RelativeLocation, and SasBlobToken from the output results for output2 and pasting the complete URL into the browser address bar.
Examine the results to determine if the newly trained model performs better than the existing one.
Save the BaseLocation, RelativeLocation, and SasBlobToken from the output results.
First, sign in to your Azure account from within the PowerShell environment by using the Connect-AzAccount cmdlet.
Next, get the Web Service Definition object by calling the Get-AzMlWebService cmdlet.
$wsd = Get-AzMlWebService -Name 'RetrainSamplePre.2016.8.17.0.3.51.237' -ResourceGroupName 'Default-MachineLearning-SouthCentralUS'
To determine the resource group name of an existing web service, run the Get-AzMlWebService cmdlet without any parameters to display the web services in your subscription. Locate the web service, and then look at its web service ID. The name of the resource group is the fourth element in the ID, just after the resourceGroups element. In the following example, the resource group name is Default-MachineLearning-SouthCentralUS.
Properties : Microsoft.Azure.Management.MachineLearning.WebServices.Models.WebServicePropertiesForGraph
Id : /subscriptions/<subscription ID>/resourceGroups/Default-MachineLearning-SouthCentralUS/providers/Microsoft.MachineLearning/webServices/RetrainSamplePre.2016.8.17.0.3.51.237
Name : RetrainSamplePre.2016.8.17.0.3.51.237
Location : South Central US
Type : Microsoft.MachineLearning/webServices
Tags : {}
Alternatively, to determine the resource group name of an existing web service, sign in to the Machine Learning Web Services portal. Select the web service. The resource group name is the fifth element of the URL of the web service, just after the resourceGroups element. In the following example, the resource group name is Default-MachineLearning-SouthCentralUS.
https://services.azureml.net/subscriptions/<subscription ID>/resourceGroups/Default-MachineLearning-SouthCentralUS/providers/Microsoft.MachineLearning/webServices/RetrainSamplePre.2016.8.17.0.3.51.237
To modify the definition of the trained model to use the newly trained model, you must first use the Export-AzMlWebService cmdlet to export it to a JSON-format file.
Export-AzMlWebService -WebService $wsd -OutputFile "C:\temp\mlservice_export.json"
In the assets, locate the [trained model], update the uri value in the locationInfo node with the URI of the ilearner blob. The URI is generated by combining the BaseLocation and the RelativeLocation from the output of the BES retraining call.
"asset3": {
"name": "Retrain Sample [trained model]",
"type": "Resource",
"locationInfo": {
"uri": "https://mltestaccount.blob.core.windows.net/azuremlassetscontainer/baca7bca650f46218633552c0bcbba0e.ilearner"
},
"outputPorts": {
"Results dataset": {
"type": "Dataset"
}
}
},
Use the Import-AzMlWebService cmdlet to convert the modified JSON file back into a Web Service Definition object that you can use to update the predicative experiment.
$wsd = Import-AzMlWebService -InputFile "C:\temp\mlservice_export.json"
Finally, use the Update-AzMlWebService cmdlet to update the predictive experiment.
Update-AzMlWebService -Name 'RetrainSamplePre.2016.8.17.0.3.51.237' -ResourceGroupName 'Default-MachineLearning-SouthCentralUS'
To learn more about how to manage web services or keep track of multiple experiments runs, see the following articles:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in