Skip to content

Commit db25c3a

Browse files
committed
reference code snippets
1 parent 6462492 commit db25c3a

File tree

2 files changed

+44
-67
lines changed

2 files changed

+44
-67
lines changed

.openpublishing.publish.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@
259259
"url": "https://github.com/Azure-Samples/cognitive-services-java-sdk-samples",
260260
"branch": "master",
261261
"branch_mapping": {}
262+
},
263+
{
264+
"path_to_root": "aml-sdk-samples",
265+
"url": "https://github.com/Azure/MachineLearningNotebooks",
266+
"branch": "sdk-codetest",
267+
"branch_mapping": {}
262268
}
263269
],
264270
"branch_target_mapping": {

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

Lines changed: 38 additions & 67 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,78 +55,45 @@ 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

11694
Find a value for `<azure-subscription-id>` in the [subscriptions list in the Azure portal](https://ms.portal.azure.com/#blade/Microsoft_Azure_Billing/SubscriptionsBlade). Use any subscription in which your role is owner or contributor.
11795

118-
```python
119-
from azureml.core import Workspace
120-
ws = Workspace.create(name='myworkspace',
121-
subscription_id='<azure-subscription-id>',
122-
resource_group='myresourcegroup',
123-
create_resource_group=True,
124-
location='eastus2' # or other supported Azure region
125-
)
126-
```
96+
[!code-python[](~/aml-sdk-samples/ignore/doc-qa/quickstart-create-workspace-with-python/quickstart.py?name=getDetails)]
12797

12898
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.
12999

@@ -139,14 +109,8 @@ Save the details of your workspace in a configuration file into the current dire
139109

140110
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.
141111

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

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

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

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

163127
Write some code that uses the basic APIs of the SDK to track experiment runs.
164128

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

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-
```
183131

184132
## View logged results
185133
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 +146,8 @@ Use the link to view the logged values in the Azure portal in your browser.
198146
199147
If you don't plan to use the resources you created here, delete them so you don't incur any charges.
200148

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

205152
## Next steps
206153

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

215-
```sh
162+
```shell
216163
conda install -y cython matplotlib scikit-learn pandas numpy
217164
pip install azureml-sdk[automl]
165+
166+
# install run history widget
167+
jupyter nbextension install --py --user azureml.train.widgets
168+
169+
# enable run history widget
170+
jupyter nbextension enable --py --user azureml.train.widgets
171+
```
172+
173+
You can also use different "extra" keywords to install additional components of the SDK.
174+
175+
```shell
176+
# install the base SDK and auto ml components
177+
pip install azureml-sdk[automl]
178+
179+
# install the base SDK and model explainability component
180+
pip install azureml-sdk[explain]
181+
182+
# install the base SDK and experimental components
183+
pip install azureml-sdk[contrib]
184+
185+
# install the base SDK and automl components in Azure Databricks environment
186+
# read more at: https://github.com/Azure/MachineLearningNotebooks/tree/master/databricks
187+
pip install azureml-sdk[databricks]
218188
```
219189

190+
220191
After you install these packages, follow the tutorials to train and deploy a model.
221192

222193
> [!div class="nextstepaction"]

0 commit comments

Comments
 (0)