Configure Model Hyperparameters with Azure ML: Best Practices and Examples

Defining Sampling Space for 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 provided defines the parameter space for a model's hyperparameters and uses Bayesian parameter sampling method to select the best hyperparameters for improving the performance of the primary metric.

Bayesian parameter sampling is a method used in hyperparameter tuning that involves selecting hyperparameters based on the results of previous experiments. It works by building a probability model of the function that maps the hyperparameters to the performance metric. This probability model is updated based on the results of each experiment, and the next set of hyperparameters to be tried is selected by sampling from this updated model.

The script defines the my_parameter_space dictionary, which contains two hyperparameters: batch_size and keep_probability. The batch_size hyperparameter has four possible values to choose from: 8, 16, 32, and 64. The keep_probability hyperparameter is defined using the uniform method, which specifies a continuous range between 0.05 and 0.1.

The param_sampling variable is then initialized using BayesianParameterSampling(my_parameter_space). This tells Azure ML to use Bayesian parameter sampling to select the best hyperparameters for the model.

Therefore, the script provided fulfills the requirement of configuring the model's hyperparameters and using a sampling method which picks samples based on the result of previous runs, in order to improve the performance in the primary metric. The correct answer is A. Yes.