To start using the Azure ML service, we can either create a workspace programmatically or by using Azure portal.
If we want to use the Azure portal (which can be found at the following link: https://portal.azure.com), follow these steps:
- First, search for machine learning on the Azure portal
- We then need to provide a name for the workspace, which in our case will be iiot-book-ml-workspace
- Choose the standard resource group, iiot-book-res, and then click on the Create button, as shown in the following screenshot:
After that, we can access the Azure Notebook by clicking on the Experiments tab in the workspace that we just created, then clicking on Open Azure Notebooks, as shown in the following screenshot:
Note that when we create a workspace, Azure instantiates additional services, as indicated by the dashed rectangle in the preceding screenshot.
To create a workspace programmatically, follow these steps:
- From the command line, then install the Jupyter Notebook and the Azure ML SDK:
$ pip install azureml-sdk[notebooks]
$ pip install jupyter
- Then, we can start our Jupyter Notebook. From the command line, run the following command:
$ jupyter notebook
- We need to create a new notebook with the following code:
import azureml.core
print(azureml.core.VERSION)
from azureml.core import Workspace
ws = Workspace.create(name='iiot-book-ml-workspace',
subscription_id='<subscription-id>',
resource_group='iiot-book-res',
create_resource_group=True,
location='eastus2'
)
# store information on the configuration file
ws.write_config()
# see the details
ws.get_details()
# write here your experiment
# …
# clean the workspace
ws.delete(delete_dependent_resources=True)
To get the subscription ID, we can search for it on the Azure portal, as shown in the following screenshot:
Instead of creating the workspace every time, we can save the configuration in a config.json file and restore it with the following Python code:
ws = Workspace.from_config()