Skip to content

Commit 5f8b7e8

Browse files
authored
Merge pull request #57774 from sdgilley/sdg-m2
reference code snippets
2 parents 0c44ffe + e6034dc commit 5f8b7e8

File tree

2 files changed

+47
-63
lines changed

2 files changed

+47
-63
lines changed

.openpublishing.publish.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@
260260
"branch": "master",
261261
"branch_mapping": {}
262262
},
263+
{
264+
"path_to_root": "aml-sdk-samples",
265+
"url": "https://github.com/Azure/MachineLearningNotebooks",
266+
"branch": "sdk-codetest",
267+
"branch_mapping": {}
268+
},
263269
{
264270
"path_to_root": "cognitive-services-vision-csharp-sdk-quickstarts",
265271
"url": "https://github.com/Azure-Samples/cognitive-services-vision-csharp-sdk-quickstarts",

articles/machine-learning/service/quickstart-create-workspace-with-python.md

Lines changed: 41 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ The following Azure resources are added automatically to your workspace when the
3434
- [Azure Application Insights](https://azure.microsoft.com/services/application-insights/)
3535
- [Azure Key Vault](https://azure.microsoft.com/services/key-vault/)
3636

37+
>[!NOTE]
38+
> Code in this article was tested with Azure Machine Learning SDK version 0.1.74
39+
3740
If you don’t have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
3841

3942

@@ -52,64 +55,39 @@ Before you install the SDK, we recommend that you create an isolated Python envi
5255

5356
Open a command-line window. Then create a new conda environment named `myenv` with Python 3.6.
5457

55-
```sh
58+
```shell
5659
conda create -n myenv -y Python=3.6
5760
```
5861

5962
Activate the environment.
6063

61-
```sh
64+
```shell
6265
conda activate myenv
6366
```
6467

6568
### Install the SDK
6669

6770
In the activated conda environment, install the SDK. The below command installs the core components of the Machine Learning SDK. It also installs a Jupyter Notebook server in the `myenv` conda environment. The installation takes a few minutes to finish, depending on the configuration of your machine.
6871

69-
```sh
72+
```shell
7073
# install the base SDK and Jupyter Notebook
7174
pip install azureml-sdk[notebooks]
72-
73-
# install run histry widget
74-
jupyter nbextension install --py --user azureml.train.widgets
75-
76-
# enable run histry widget
77-
jupyter nbextension enable --py --user azureml.train.widgets
7875
```
7976

80-
You can also use different "extra" keywords to install additional components of the SDK.
81-
82-
```sh
83-
# install the base SDK and auto ml components
84-
pip install azureml-sdk[automl]
85-
86-
# install the base SDK and model explainability component
87-
pip install azureml-sdk[explain]
88-
89-
# install the base SDK and experimental components
90-
pip install azureml-sdk[contrib]
91-
92-
# install the base SDK and automl components in Azure Databricks environment
93-
# read more at: https://github.com/Azure/MachineLearningNotebooks/tree/master/databricks
94-
pip install azureml-sdk[databricks]
95-
```
9677

9778

9879
## Create a workspace
9980

10081
To launch the Jupyter Notebook, enter this command.
101-
```sh
82+
```shell
10283
jupyter notebook
10384
```
10485

10586
In the browser window, create a new notebook by using the default `Python 3` kernel.
10687

10788
To display the SDK version, enter the following Python code in a notebook cell and execute it.
10889

109-
```python
110-
import azureml.core
111-
print(azureml.core.VERSION)
112-
```
90+
[!code-python[](~/aml-sdk-samples/ignore/doc-qa/quickstart-create-workspace-with-python/quickstart.py?name=import)]
11391

11492
Create a new Azure resource group and a new workspace.
11593

@@ -118,35 +96,28 @@ Find a value for `<azure-subscription-id>` in the [subscriptions list in the Azu
11896
```python
11997
from azureml.core import Workspace
12098
ws = Workspace.create(name='myworkspace',
121-
subscription_id='<azure-subscription-id>',
99+
subscription_id='<azure-subscription-id>',
122100
resource_group='myresourcegroup',
123101
create_resource_group=True,
124-
location='eastus2' # or other supported Azure region
102+
location='eastus2' # or other supported Azure region
125103
)
126104
```
127105

128106
Executing the preceding code might trigger a new browser window for you to sign into your Azure account. After you sign in, the authentication token is cached locally.
129107

130108
To see the workspace details, such as associated storage, container registry, and key vault, enter the following code.
131109

132-
```python
133-
ws.get_details()
134-
```
110+
[!code-python[](~/aml-sdk-samples/ignore/doc-qa/quickstart-create-workspace-with-python/quickstart.py?name=getDetails)]
111+
135112

136113
## Write a configuration file
137114

138115
Save the details of your workspace in a configuration file into the current directory. This file is called 'aml_config\config.json'.
139116

140117
This workspace configuration file makes it easy to load this same workspace later. You can load it with other notebooks and scripts in the same directory or a subdirectory.
141118

142-
```python
143-
# Create the configuration file.
144-
ws.write_config()
119+
[!code-python[](~/aml-sdk-samples/ignore/doc-qa/quickstart-create-workspace-with-python/quickstart.py?name=writeConfig)]
145120

146-
# Use this code to load the workspace from
147-
# other scripts and notebooks in this directory.
148-
# ws = Workspace.from_config()
149-
```
150121

151122
The `write_config()` API call creates the configuration file in the current directory. The `config.json` file contains the following script.
152123

@@ -162,24 +133,8 @@ The `write_config()` API call creates the configuration file in the current dire
162133

163134
Write some code that uses the basic APIs of the SDK to track experiment runs.
164135

165-
```python
166-
from azureml.core import Experiment
167-
168-
# create a new experiment
169-
exp = Experiment(workspace=ws, name='myexp')
136+
[!code-python[](~/aml-sdk-samples/ignore/doc-qa/quickstart-create-workspace-with-python/quickstart.py?name=useWs)]
170137

171-
# start a run
172-
run = exp.start_logging()
173-
174-
# log a number
175-
run.log('my magic number', 42)
176-
177-
# log a list (Fibonacci numbers)
178-
run.log_list('my list', [1, 1, 2, 3, 5, 8, 13, 21, 34, 55])
179-
180-
# finish the run
181-
run.complete()
182-
```
183138

184139
## View logged results
185140
When the run finishes, you can view the experiment run in the Azure portal. Use the following code to print a URL to the results for the last run.
@@ -198,9 +153,8 @@ Use the link to view the logged values in the Azure portal in your browser.
198153
199154
If you don't plan to use the resources you created here, delete them so you don't incur any charges.
200155

201-
```python
202-
ws.delete(delete_dependent_resources=True)
203-
```
156+
[!code-python[](~/aml-sdk-samples/ignore/doc-qa/quickstart-create-workspace-with-python/quickstart.py?name=delete)]
157+
204158

205159
## Next steps
206160

@@ -212,11 +166,35 @@ You need a few more packages in your environment to use it with Machine Learning
212166
1. In the command-line window, use `Ctrl`+`C` to stop the notebook server.
213167
1. Install additional packages.
214168

215-
```sh
169+
```shell
216170
conda install -y cython matplotlib scikit-learn pandas numpy
217171
pip install azureml-sdk[automl]
172+
173+
# install run history widget
174+
jupyter nbextension install --py --user azureml.train.widgets
175+
176+
# enable run history widget
177+
jupyter nbextension enable --py --user azureml.train.widgets
218178
```
219179

180+
You can also use different "extra" keywords to install additional components of the SDK.
181+
182+
```shell
183+
# install the base SDK and auto ml components
184+
pip install azureml-sdk[automl]
185+
186+
# install the base SDK and model explainability component
187+
pip install azureml-sdk[explain]
188+
189+
# install the base SDK and experimental components
190+
pip install azureml-sdk[contrib]
191+
192+
# install the base SDK and automl components in Azure Databricks environment
193+
# read more at: https://github.com/Azure/MachineLearningNotebooks/tree/master/databricks
194+
pip install azureml-sdk[databricks]
195+
```
196+
197+
220198
After you install these packages, follow the tutorials to train and deploy a model.
221199

222200
> [!div class="nextstepaction"]

0 commit comments

Comments
 (0)