Skip to content

Commit fb4f287

Browse files
committed
update samples from Release-79 as a part of SDK release
1 parent 41366a4 commit fb4f287

File tree

39 files changed

+372
-280
lines changed

39 files changed

+372
-280
lines changed

NBSETUP.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ git clone https://github.com/Azure/MachineLearningNotebooks.git
2828
pip install azureml-sdk[notebooks,tensorboard]
2929

3030
# install model explainability component
31-
pip install azureml-sdk[explain]
31+
pip install azureml-sdk[interpret]
3232

3333
# install automated ml components
3434
pip install azureml-sdk[automl]
@@ -86,7 +86,7 @@ If you need additional Azure ML SDK components, you can either modify the Docker
8686
pip install azureml-sdk[automl]
8787

8888
# install the core SDK and model explainability component
89-
pip install azureml-sdk[explain]
89+
pip install azureml-sdk[interpret]
9090

9191
# install the core SDK and experimental components
9292
pip install azureml-sdk[contrib]

configuration.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"source": [
104104
"import azureml.core\n",
105105
"\n",
106-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
106+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
107107
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
108108
]
109109
},

contrib/fairness/fairlearn-azureml-mitigation.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"## Introduction\n",
3939
"This notebook shows how to use [Fairlearn (an open source fairness assessment and unfairness mitigation package)](http://fairlearn.github.io) and Azure Machine Learning Studio for a binary classification problem. This example uses the well-known adult census dataset. For the purposes of this notebook, we shall treat this as a loan decision problem. We will pretend that the label indicates whether or not each individual repaid a loan in the past. We will use the data to train a predictor to predict whether previously unseen individuals will repay a loan or not. The assumption is that the model predictions are used to decide whether an individual should be offered a loan. Its purpose is purely illustrative of a workflow including a fairness dashboard - in particular, we do **not** include a full discussion of the detailed issues which arise when considering fairness in machine learning. For such discussions, please [refer to the Fairlearn website](http://fairlearn.github.io/).\n",
4040
"\n",
41-
"We will apply the [grid search algorithm](https://fairlearn.github.io/api_reference/fairlearn.reductions.html#fairlearn.reductions.GridSearch) from the Fairlearn package using a specific notion of fairness called Demographic Parity. This produces a set of models, and we will view these in a dashboard both locally and in the Azure Machine Learning Studio.\n",
41+
"We will apply the [grid search algorithm](https://fairlearn.github.io/master/api_reference/fairlearn.reductions.html#fairlearn.reductions.GridSearch) from the Fairlearn package using a specific notion of fairness called Demographic Parity. This produces a set of models, and we will view these in a dashboard both locally and in the Azure Machine Learning Studio.\n",
4242
"\n",
4343
"### Setup\n",
4444
"\n",
@@ -98,8 +98,11 @@
9898
"metadata": {},
9999
"outputs": [],
100100
"source": [
101-
"from sklearn.datasets import fetch_openml\n",
102-
"data = fetch_openml(data_id=1590, as_frame=True)\n",
101+
"from utilities import fetch_openml_with_retries\n",
102+
"\n",
103+
"data = fetch_openml_with_retries(data_id=1590)\n",
104+
" \n",
105+
"# Extract the items we want\n",
103106
"X_raw = data.data\n",
104107
"Y = (data.target == '>50K') * 1\n",
105108
"\n",

contrib/fairness/upload-fairness-dashboard.ipynb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@
9898
"metadata": {},
9999
"outputs": [],
100100
"source": [
101-
"from sklearn.datasets import fetch_openml\n",
102-
"data = fetch_openml(data_id=1590, as_frame=True)\n",
101+
"from utilities import fetch_openml_with_retries\n",
102+
"\n",
103+
"data = fetch_openml_with_retries(data_id=1590)\n",
104+
" \n",
105+
"# Extract the items we want\n",
103106
"X_raw = data.data\n",
104107
"Y = (data.target == '>50K') * 1"
105108
]

contrib/fairness/utilities.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ---------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# ---------------------------------------------------------
4+
5+
"""Utilities for azureml-contrib-fairness notebooks."""
6+
7+
from sklearn.datasets import fetch_openml
8+
import time
9+
10+
11+
def fetch_openml_with_retries(data_id, max_retries=4, retry_delay=60):
12+
"""Fetch a given dataset from OpenML with retries as specified."""
13+
for i in range(max_retries):
14+
try:
15+
print("Download attempt {0} of {1}".format(i + 1, max_retries))
16+
data = fetch_openml(data_id=data_id, as_frame=True)
17+
break
18+
except Exception as e:
19+
print("Download attempt failed with exception:")
20+
print(e)
21+
if i + 1 != max_retries:
22+
print("Will retry after {0} seconds".format(retry_delay))
23+
time.sleep(retry_delay)
24+
retry_delay = retry_delay * 2
25+
else:
26+
raise RuntimeError("Unable to download dataset from OpenML")
27+
28+
return data

how-to-use-azureml/automated-machine-learning/automl_env.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dependencies:
33
# The python interpreter version.
44
# Currently Azure ML only supports 3.5.2 and later.
55
- pip<=19.3.1
6-
- python>=3.5.2,<3.6.8
6+
- python>=3.5.2,<3.8
77
- nb_conda
88
- boto3==1.15.18
99
- matplotlib==2.1.0
@@ -21,8 +21,8 @@ dependencies:
2121

2222
- pip:
2323
# Required packages for AzureML execution, history, and data preparation.
24-
- azureml-widgets~=1.18.0
24+
- azureml-widgets~=1.19.0
2525
- pytorch-transformers==1.0.0
2626
- spacy==2.1.8
2727
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
28-
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.18.0/validated_win32_requirements.txt [--no-deps]
28+
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.19.0/validated_win32_requirements.txt [--no-deps]

how-to-use-azureml/automated-machine-learning/automl_env_linux.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dependencies:
33
# The python interpreter version.
44
# Currently Azure ML only supports 3.5.2 and later.
55
- pip<=19.3.1
6-
- python>=3.5.2,<3.6.8
6+
- python>=3.5.2,<3.8
77
- nb_conda
88
- boto3==1.15.18
99
- matplotlib==2.1.0
@@ -21,9 +21,9 @@ dependencies:
2121

2222
- pip:
2323
# Required packages for AzureML execution, history, and data preparation.
24-
- azureml-widgets~=1.18.0
24+
- azureml-widgets~=1.19.0
2525
- pytorch-transformers==1.0.0
2626
- spacy==2.1.8
2727
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
28-
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.18.0/validated_linux_requirements.txt [--no-deps]
28+
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.19.0/validated_linux_requirements.txt [--no-deps]
2929

how-to-use-azureml/automated-machine-learning/automl_env_mac.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencies:
44
# Currently Azure ML only supports 3.5.2 and later.
55
- pip<=19.3.1
66
- nomkl
7-
- python>=3.5.2,<3.6.8
7+
- python>=3.5.2,<3.8
88
- nb_conda
99
- boto3==1.15.18
1010
- matplotlib==2.1.0
@@ -22,8 +22,8 @@ dependencies:
2222

2323
- pip:
2424
# Required packages for AzureML execution, history, and data preparation.
25-
- azureml-widgets~=1.18.0
25+
- azureml-widgets~=1.19.0
2626
- pytorch-transformers==1.0.0
2727
- spacy==2.1.8
2828
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
29-
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.18.0/validated_darwin_requirements.txt [--no-deps]
29+
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.19.0/validated_darwin_requirements.txt [--no-deps]

how-to-use-azureml/automated-machine-learning/classification-bank-marketing-all-features/auto-ml-classification-bank-marketing-all-features.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"metadata": {},
106106
"outputs": [],
107107
"source": [
108-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
108+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
109109
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
110110
]
111111
},

how-to-use-azureml/automated-machine-learning/classification-credit-card-fraud/auto-ml-classification-credit-card-fraud.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"metadata": {},
9494
"outputs": [],
9595
"source": [
96-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
96+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
9797
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
9898
]
9999
},

how-to-use-azureml/automated-machine-learning/classification-text-dnn/auto-ml-classification-text-dnn.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"metadata": {},
9797
"outputs": [],
9898
"source": [
99-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
99+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
100100
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
101101
]
102102
},
@@ -298,7 +298,7 @@
298298
" compute_target=compute_target,\n",
299299
" training_data=train_dataset,\n",
300300
" label_column_name=target_column_name,\n",
301-
" blocked_models = ['LightGBM'],\n",
301+
" blocked_models = ['LightGBM', 'XGBoostClassifier'],\n",
302302
" **automl_settings\n",
303303
" )"
304304
]

how-to-use-azureml/automated-machine-learning/continuous-retraining/auto-ml-continuous-retraining.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"metadata": {},
8282
"outputs": [],
8383
"source": [
84-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
84+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
8585
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
8686
]
8787
},

how-to-use-azureml/automated-machine-learning/experimental/regression-model-proxy/auto-ml-regression-model-proxy.ipynb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"import logging\n",
6969
"\n",
7070
"from matplotlib import pyplot as plt\n",
71+
"import json\n",
7172
"import numpy as np\n",
7273
"import pandas as pd\n",
7374
" \n",
@@ -92,7 +93,7 @@
9293
"metadata": {},
9394
"outputs": [],
9495
"source": [
95-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
96+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
9697
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
9798
]
9899
},
@@ -322,6 +323,24 @@
322323
"print(best_run)"
323324
]
324325
},
326+
{
327+
"cell_type": "markdown",
328+
"metadata": {},
329+
"source": [
330+
"#### Show hyperparameters\n",
331+
"Show the model pipeline used for the best run with its hyperparameters."
332+
]
333+
},
334+
{
335+
"cell_type": "code",
336+
"execution_count": null,
337+
"metadata": {},
338+
"outputs": [],
339+
"source": [
340+
"run_properties = json.loads(best_run.get_details()['properties']['pipeline_script'])\n",
341+
"print(json.dumps(run_properties, indent = 1)) "
342+
]
343+
},
325344
{
326345
"cell_type": "markdown",
327346
"metadata": {},

how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/auto-ml-forecasting-beer-remote.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"metadata": {},
114114
"outputs": [],
115115
"source": [
116-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
116+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
117117
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
118118
]
119119
},

how-to-use-azureml/automated-machine-learning/forecasting-beer-remote/helper.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from azureml.core.conda_dependencies import CondaDependencies
44
from azureml.train.estimator import Estimator
55
from azureml.core.run import Run
6+
from azureml.automl.core.shared import constants
67

78

89
def split_fraction_by_grain(df, fraction, time_column_name,
910
grain_column_names=None):
10-
1111
if not grain_column_names:
1212
df['tmp_grain_column'] = 'grain'
1313
grain_column_names = ['tmp_grain_column']
@@ -17,10 +17,10 @@ def split_fraction_by_grain(df, fraction, time_column_name,
1717
.groupby(grain_column_names, group_keys=False))
1818

1919
df_head = df_grouped.apply(lambda dfg: dfg.iloc[:-int(len(dfg) *
20-
fraction)] if fraction > 0 else dfg)
20+
fraction)] if fraction > 0 else dfg)
2121

2222
df_tail = df_grouped.apply(lambda dfg: dfg.iloc[-int(len(dfg) *
23-
fraction):] if fraction > 0 else dfg[:0])
23+
fraction):] if fraction > 0 else dfg[:0])
2424

2525
if 'tmp_grain_column' in grain_column_names:
2626
for df2 in (df, df_head, df_tail):
@@ -59,11 +59,13 @@ def get_result_df(remote_run):
5959
'primary_metric', 'Score'])
6060
goal_minimize = False
6161
for run in children:
62-
if('run_algorithm' in run.properties and 'score' in run.properties):
62+
if run.get_status().lower() == constants.RunState.COMPLETE_RUN \
63+
and 'run_algorithm' in run.properties and 'score' in run.properties:
64+
# We only count in the completed child runs.
6365
summary_df[run.id] = [run.id, run.properties['run_algorithm'],
6466
run.properties['primary_metric'],
6567
float(run.properties['score'])]
66-
if('goal' in run.properties):
68+
if ('goal' in run.properties):
6769
goal_minimize = run.properties['goal'].split('_')[-1] == 'min'
6870

6971
summary_df = summary_df.T.sort_values(
@@ -118,7 +120,6 @@ def run_multiple_inferences(summary_df, train_experiment, test_experiment,
118120
compute_target, script_folder, test_dataset,
119121
lookback_dataset, max_horizon, target_column_name,
120122
time_column_name, freq):
121-
122123
for run_name, run_summary in summary_df.iterrows():
123124
print(run_name)
124125
print(run_summary)

how-to-use-azureml/automated-machine-learning/forecasting-bike-share/auto-ml-forecasting-bike-share.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"metadata": {},
8888
"outputs": [],
8989
"source": [
90-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
90+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
9191
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
9292
]
9393
},

how-to-use-azureml/automated-machine-learning/forecasting-bike-share/forecasting_script.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import argparse
2-
import azureml.train.automl
3-
from azureml.core import Run
2+
from azureml.core import Dataset, Run
43
from sklearn.externals import joblib
54

6-
75
parser = argparse.ArgumentParser()
86
parser.add_argument(
97
'--target_column_name', type=str, dest='target_column_name',
108
help='Target Column Name')
9+
parser.add_argument(
10+
'--test_dataset', type=str, dest='test_dataset',
11+
help='Test Dataset')
1112

1213
args = parser.parse_args()
1314
target_column_name = args.target_column_name
15+
test_dataset_id = args.test_dataset
1416

1517
run = Run.get_context()
16-
# get input dataset by name
17-
test_dataset = run.input_datasets['test_data']
18+
ws = run.experiment.workspace
1819

19-
df = test_dataset.to_pandas_dataframe().reset_index(drop=True)
20+
# get the input dataset by id
21+
test_dataset = Dataset.get_by_id(ws, id=test_dataset_id)
2022

2123
X_test_df = test_dataset.drop_columns(columns=[target_column_name]).to_pandas_dataframe().reset_index(drop=True)
2224
y_test_df = test_dataset.with_timestamp_columns(None).keep_columns(columns=[target_column_name]).to_pandas_dataframe()
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
from azureml.train.estimator import Estimator
1+
from azureml.core import ScriptRunConfig
22

33

4-
def run_rolling_forecast(test_experiment, compute_target, train_run, test_dataset,
5-
target_column_name, inference_folder='./forecast'):
4+
def run_rolling_forecast(test_experiment, compute_target, train_run,
5+
test_dataset, target_column_name,
6+
inference_folder='./forecast'):
67
train_run.download_file('outputs/model.pkl',
78
inference_folder + '/model.pkl')
89

910
inference_env = train_run.get_environment()
1011

11-
est = Estimator(source_directory=inference_folder,
12-
entry_script='forecasting_script.py',
13-
script_params={
14-
'--target_column_name': target_column_name
15-
},
16-
inputs=[test_dataset.as_named_input('test_data')],
17-
compute_target=compute_target,
18-
environment_definition=inference_env)
12+
config = ScriptRunConfig(source_directory=inference_folder,
13+
script='forecasting_script.py',
14+
arguments=['--target_column_name',
15+
target_column_name,
16+
'--test_dataset',
17+
test_dataset.as_named_input(test_dataset.name)],
18+
compute_target=compute_target,
19+
environment=inference_env)
1920

20-
run = test_experiment.submit(est,
21-
tags={
22-
'training_run_id': train_run.id,
23-
'run_algorithm': train_run.properties['run_algorithm'],
24-
'valid_score': train_run.properties['score'],
25-
'primary_metric': train_run.properties['primary_metric']
26-
})
21+
run = test_experiment.submit(config,
22+
tags={'training_run_id':
23+
train_run.id,
24+
'run_algorithm':
25+
train_run.properties['run_algorithm'],
26+
'valid_score':
27+
train_run.properties['score'],
28+
'primary_metric':
29+
train_run.properties['primary_metric']})
2730

2831
run.log("run_algorithm", run.tags['run_algorithm'])
2932
return run

how-to-use-azureml/automated-machine-learning/forecasting-energy-demand/auto-ml-forecasting-energy-demand.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"metadata": {},
9898
"outputs": [],
9999
"source": [
100-
"print(\"This notebook was created using version 1.18.0 of the Azure ML SDK\")\n",
100+
"print(\"This notebook was created using version 1.19.0 of the Azure ML SDK\")\n",
101101
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
102102
]
103103
},

0 commit comments

Comments
 (0)