Create ML Workspace from SDK | Azure DP-100 Exam Question

Connecting to Azure ML Workspace from SDK

Question

You have created a ML workspace from SDK using the following script:

# create workspace from azureml.core import Workspace ws = Workspace.create(name='myworkspace',  subscription_id='<azure-subscription-id>',  resource_group='myresourcegroup',  create_resource_group=True,  location='eastus2'  ) ws.write_config() ... 
For your machine learning experiments, you have several scripts, from which you need to connect to the workspace by the simplest and most flexible way.

... # connect to workspace from azureml.core import Workspace <insert code here> 
Which code segment fits best to the purpose?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer: D.

The correct code segment that fits best to connect to the workspace by the simplest and most flexible way is D. ws=Workspace.from_config().

The script provided in the question creates a new Machine Learning Workspace using the Azure ML Python SDK. The workspace is created with a name, subscription ID, resource group name, location, and create_resource_group=True flag which creates a new resource group if it doesn't exist already.

To connect to this workspace, there are multiple ways, but the simplest and most flexible way is to use the Workspace.from_config() method, which reads the configuration file generated by the workspace.write_config() method in the previous script and returns a Workspace object.

This method loads the workspace configuration file from the default location, which is the current working directory or a specified directory, and returns a Workspace object that represents the workspace. The advantage of using this method is that it provides a flexible way to connect to a workspace from different environments, like a local machine or a remote compute instance, without hard-coding the workspace credentials.

Option A, ws=Workspace.read_config(), is not the best option since it reads the workspace configuration file and returns a Workspace object, but it expects the configuration file to be in a specific location, which may not be practical in different environments.

Option B, ws=Workspace.get(), is not a valid option since the get() method requires a subscription ID, resource group name, and workspace name as input parameters, which is not provided in the code snippet.

Option C, ws=get_connection(), is not a valid option since the get_connection() method is not defined in the azureml.core.Workspace class.