Azure ML Hyperparameter Sampling - Designing and Implementing a Data Science Solution on Azure

Configuring Hyperparameters in Azure ML

Question

You are running experiments in Azure ML and you want to configure the model's hyperparameters.

You need to define the sampling space for two parameters and you want Azure ML to use a sampling method which picks samples based on the result of previous runs, in order to improve the performance in the primary metric.

# define parameter space from azureml.train.hyperdrive import BayesianParameterSampling, choice, uniform my_parameter_space = {  'batch_size': choice(8, 16, 32, 64), "keep_probability": uniform(0.05, 0.1) } param_sampling = BayesianParameterSampling(my_parameter_space) ...
Does the script above fulfills your requirement?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B.

Answer: A.

Option A is CORRECT because the Bayesian parameter sampling is the right choice, and this sampling method supports choice, uniform, and quniform distributions.

Therefore, the code is correct.

Option B is incorrect because the code defines the parameter search space for two parameters,batch_size and keep_probability, with the Bayesian sampling method.

Bayesian sampling improves sampling based on the result of previous runs, and it can be used with either choice or uniform methods.

Reference:

The script above does not fulfill the requirement of using a sampling method which picks samples based on the result of previous runs to improve the performance in the primary metric. The script uses BayesianParameterSampling, which is a sampling method that uses Bayesian optimization to iteratively improve the model based on the results of previous runs. However, it does not specify the primary metric that should be used for optimization.

In order to configure the sampling method to pick samples based on the result of previous runs to improve the performance in the primary metric, the script should also include the following code to define the primary metric and set it as the optimization target:

python
from azureml.train.hyperdrive import PrimaryMetricGoal primary_metric_name = 'accuracy' primary_metric_goal = PrimaryMetricGoal.MAXIMIZE

The above code defines the primary metric to be "accuracy" and sets the optimization goal to maximize it. This ensures that the sampling method will pick samples based on the result of previous runs in order to improve the accuracy of the model.

Therefore, the corrected script should look like this:

cpp
# define parameter space from azureml.train.hyperdrive import BayesianParameterSampling, choice, uniform, PrimaryMetricGoal my_parameter_space = { "batch_size": choice(8, 16, 32, 64), "keep_probability": uniform(0.05, 0.1) } # define primary metric primary_metric_name = 'accuracy' primary_metric_goal = PrimaryMetricGoal.MAXIMIZE # configure parameter sampling param_sampling = BayesianParameterSampling( my_parameter_space, primary_metric_name=primary_metric_name, primary_metric_goal=primary_metric_goal )

With these changes, the script will use BayesianParameterSampling to iteratively improve the model based on the results of previous runs, with the goal of maximizing the accuracy of the model.