Skip to content

Commit 700ab2d

Browse files
authored
Merge pull request Azure#1489 from Azure/release_update/Release-97
update samples from Release-97 as a part of SDK 1.29.0 release
2 parents 467630f + ec9a5a0 commit 700ab2d

File tree

40 files changed

+624
-341
lines changed

40 files changed

+624
-341
lines changed

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.28.0 of the Azure ML SDK\")\n",
106+
"print(\"This notebook was created using version 1.29.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: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@
4646
"Please see the [configuration notebook](../../configuration.ipynb) for information about creating one, if required.\n",
4747
"This notebook also requires the following packages:\n",
4848
"* `azureml-contrib-fairness`\n",
49-
"* `fairlearn==0.4.6` (v0.5.0 will work with minor modifications)\n",
49+
"* `fairlearn>=0.6.2` (pre-v0.5.0 will work with minor modifications)\n",
5050
"* `joblib`\n",
5151
"* `liac-arff`\n",
52+
"* `raiwidgets==0.4.0`\n",
5253
"\n",
5354
"Fairlearn relies on features introduced in v0.22.1 of `scikit-learn`. If you have an older version already installed, please uncomment and run the following cell:"
5455
]
@@ -85,7 +86,7 @@
8586
"outputs": [],
8687
"source": [
8788
"from fairlearn.reductions import GridSearch, DemographicParity, ErrorRate\n",
88-
"from fairlearn.widget import FairlearnDashboard\n",
89+
"from raiwidgets import FairnessDashboard\n",
8990
"\n",
9091
"from sklearn.compose import ColumnTransformer\n",
9192
"from sklearn.impute import SimpleImputer\n",
@@ -256,9 +257,9 @@
256257
"metadata": {},
257258
"outputs": [],
258259
"source": [
259-
"FairlearnDashboard(sensitive_features=A_test, sensitive_feature_names=['Sex', 'Race'],\n",
260-
" y_true=y_test,\n",
261-
" y_pred={\"unmitigated\": unmitigated_predictor.predict(X_test)})"
260+
"FairnessDashboard(sensitive_features=A_test,\n",
261+
" y_true=y_test,\n",
262+
" y_pred={\"unmitigated\": unmitigated_predictor.predict(X_test)})"
262263
]
263264
},
264265
{
@@ -311,8 +312,8 @@
311312
"sweep.fit(X_train, y_train,\n",
312313
" sensitive_features=A_train.sex)\n",
313314
"\n",
314-
"# For Fairlearn v0.5.0, need sweep.predictors_\n",
315-
"predictors = sweep._predictors"
315+
"# For Fairlearn pre-v0.5.0, need sweep._predictors\n",
316+
"predictors = sweep.predictors_"
316317
]
317318
},
318319
{
@@ -329,16 +330,14 @@
329330
"outputs": [],
330331
"source": [
331332
"errors, disparities = [], []\n",
332-
"for m in predictors:\n",
333-
" classifier = lambda X: m.predict(X)\n",
334-
" \n",
333+
"for predictor in predictors:\n",
335334
" error = ErrorRate()\n",
336335
" error.load_data(X_train, pd.Series(y_train), sensitive_features=A_train.sex)\n",
337336
" disparity = DemographicParity()\n",
338337
" disparity.load_data(X_train, pd.Series(y_train), sensitive_features=A_train.sex)\n",
339338
" \n",
340-
" errors.append(error.gamma(classifier)[0])\n",
341-
" disparities.append(disparity.gamma(classifier).max())\n",
339+
" errors.append(error.gamma(predictor.predict)[0])\n",
340+
" disparities.append(disparity.gamma(predictor.predict).max())\n",
342341
" \n",
343342
"all_results = pd.DataFrame( {\"predictor\": predictors, \"error\": errors, \"disparity\": disparities})\n",
344343
"\n",
@@ -387,10 +386,9 @@
387386
"metadata": {},
388387
"outputs": [],
389388
"source": [
390-
"FairlearnDashboard(sensitive_features=A_test, \n",
391-
" sensitive_feature_names=['Sex', 'Race'],\n",
392-
" y_true=y_test.tolist(),\n",
393-
" y_pred=predictions_dominant)"
389+
"FairnessDashboard(sensitive_features=A_test, \n",
390+
" y_true=y_test.tolist(),\n",
391+
" y_pred=predictions_dominant)"
394392
]
395393
},
396394
{
@@ -409,7 +407,7 @@
409407
"<a id=\"AzureUpload\"></a>\n",
410408
"## Uploading a Fairness Dashboard to Azure\n",
411409
"\n",
412-
"Uploading a fairness dashboard to Azure is a two stage process. The `FairlearnDashboard` invoked in the previous section relies on the underlying Python kernel to compute metrics on demand. This is obviously not available when the fairness dashboard is rendered in AzureML Studio. By default, the dashboard in Azure Machine Learning Studio also requires the models to be registered. The required stages are therefore:\n",
410+
"Uploading a fairness dashboard to Azure is a two stage process. The `FairnessDashboard` invoked in the previous section relies on the underlying Python kernel to compute metrics on demand. This is obviously not available when the fairness dashboard is rendered in AzureML Studio. By default, the dashboard in Azure Machine Learning Studio also requires the models to be registered. The required stages are therefore:\n",
413411
"1. Register the dominant models\n",
414412
"1. Precompute all the required metrics\n",
415413
"1. Upload to Azure\n",

contrib/fairness/fairlearn-azureml-mitigation.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dependencies:
33
- pip:
44
- azureml-sdk
55
- azureml-contrib-fairness
6-
- fairlearn==0.4.6
6+
- fairlearn>=0.6.2
77
- joblib
88
- liac-arff
9+
- raiwidgets==0.4.0

contrib/fairness/fairness_nb_utils.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def fetch_openml_with_retries(data_id, max_retries=4, retry_delay=60):
2121
print("Download attempt {0} of {1}".format(i + 1, max_retries))
2222
data = fetch_openml(data_id=data_id, as_frame=True)
2323
break
24-
except Exception as e:
24+
except Exception as e: # noqa: B902
2525
print("Download attempt failed with exception:")
2626
print(e)
2727
if i + 1 != max_retries:
@@ -47,7 +47,7 @@ def fetch_openml_with_retries(data_id, max_retries=4, retry_delay=60):
4747

4848

4949
def fetch_census_dataset():
50-
"""Fetch the Adult Census Dataset
50+
"""Fetch the Adult Census Dataset.
5151
5252
This uses a particular URL for the Adult Census dataset. The code
5353
is a simplified version of fetch_openml() in sklearn.
@@ -63,17 +63,35 @@ def fetch_census_dataset():
6363

6464
filename = "1595261.gz"
6565
data_url = "https://rainotebookscdn.blob.core.windows.net/datasets/"
66-
urlretrieve(data_url + filename, filename)
6766

68-
http_stream = gzip.GzipFile(filename=filename, mode='rb')
69-
70-
with closing(http_stream):
71-
def _stream_generator(response):
72-
for line in response:
73-
yield line.decode('utf-8')
74-
75-
stream = _stream_generator(http_stream)
76-
data = arff.load(stream)
67+
remaining_attempts = 5
68+
sleep_duration = 10
69+
while remaining_attempts > 0:
70+
try:
71+
urlretrieve(data_url + filename, filename)
72+
73+
http_stream = gzip.GzipFile(filename=filename, mode='rb')
74+
75+
with closing(http_stream):
76+
def _stream_generator(response):
77+
for line in response:
78+
yield line.decode('utf-8')
79+
80+
stream = _stream_generator(http_stream)
81+
data = arff.load(stream)
82+
except Exception as exc: # noqa: B902
83+
remaining_attempts -= 1
84+
print("Error downloading dataset from {} ({} attempt(s) remaining)"
85+
.format(data_url, remaining_attempts))
86+
print(exc)
87+
time.sleep(sleep_duration)
88+
sleep_duration *= 2
89+
continue
90+
else:
91+
# dataset successfully downloaded
92+
break
93+
else:
94+
raise Exception("Could not retrieve dataset from {}.".format(data_url))
7795

7896
attributes = OrderedDict(data['attributes'])
7997
arff_columns = list(attributes)

contrib/fairness/upload-fairness-dashboard.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"1. [Training Models](#TrainingModels)\n",
3131
"1. [Logging in to AzureML](#LoginAzureML)\n",
3232
"1. [Registering the Models](#RegisterModels)\n",
33-
"1. [Using the Fairlearn Dashboard](#LocalDashboard)\n",
33+
"1. [Using the Fairness Dashboard](#LocalDashboard)\n",
3434
"1. [Uploading a Fairness Dashboard to Azure](#AzureUpload)\n",
3535
" 1. Computing Fairness Metrics\n",
3636
" 1. Uploading to Azure\n",
@@ -48,9 +48,10 @@
4848
"Please see the [configuration notebook](../../configuration.ipynb) for information about creating one, if required.\n",
4949
"This notebook also requires the following packages:\n",
5050
"* `azureml-contrib-fairness`\n",
51-
"* `fairlearn==0.4.6` (should also work with v0.5.0)\n",
51+
"* `fairlearn>=0.6.2` (also works for pre-v0.5.0 with slight modifications)\n",
5252
"* `joblib`\n",
5353
"* `liac-arff`\n",
54+
"* `raiwidgets==0.4.0`\n",
5455
"\n",
5556
"Fairlearn relies on features introduced in v0.22.1 of `scikit-learn`. If you have an older version already installed, please uncomment and run the following cell:"
5657
]
@@ -388,12 +389,11 @@
388389
"metadata": {},
389390
"outputs": [],
390391
"source": [
391-
"from fairlearn.widget import FairlearnDashboard\n",
392+
"from raiwidgets import FairnessDashboard\n",
392393
"\n",
393-
"FairlearnDashboard(sensitive_features=A_test, \n",
394-
" sensitive_feature_names=['Sex', 'Race'],\n",
395-
" y_true=y_test.tolist(),\n",
396-
" y_pred=ys_pred)"
394+
"FairnessDashboard(sensitive_features=A_test, \n",
395+
" y_true=y_test.tolist(),\n",
396+
" y_pred=ys_pred)"
397397
]
398398
},
399399
{
@@ -403,7 +403,7 @@
403403
"<a id=\"AzureUpload\"></a>\n",
404404
"## Uploading a Fairness Dashboard to Azure\n",
405405
"\n",
406-
"Uploading a fairness dashboard to Azure is a two stage process. The `FairlearnDashboard` invoked in the previous section relies on the underlying Python kernel to compute metrics on demand. This is obviously not available when the fairness dashboard is rendered in AzureML Studio. The required stages are therefore:\n",
406+
"Uploading a fairness dashboard to Azure is a two stage process. The `FairnessDashboard` invoked in the previous section relies on the underlying Python kernel to compute metrics on demand. This is obviously not available when the fairness dashboard is rendered in AzureML Studio. The required stages are therefore:\n",
407407
"1. Precompute all the required metrics\n",
408408
"1. Upload to Azure\n",
409409
"\n",

contrib/fairness/upload-fairness-dashboard.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dependencies:
33
- pip:
44
- azureml-sdk
55
- azureml-contrib-fairness
6-
- fairlearn==0.4.6
6+
- fairlearn>=0.6.2
77
- joblib
88
- liac-arff
9+
- raiwidgets==0.4.0

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ dependencies:
2121

2222
- pip:
2323
# Required packages for AzureML execution, history, and data preparation.
24-
- azureml-widgets~=1.28.0
24+
- azureml-widgets~=1.29.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://automlresources-prod.azureedge.net/validated-requirements/1.28.0/validated_win32_requirements.txt [--no-deps]
28+
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.29.0/validated_win32_requirements.txt [--no-deps]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ dependencies:
2121

2222
- pip:
2323
# Required packages for AzureML execution, history, and data preparation.
24-
- azureml-widgets~=1.28.0
24+
- azureml-widgets~=1.29.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://automlresources-prod.azureedge.net/validated-requirements/1.28.0/validated_linux_requirements.txt [--no-deps]
28+
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.29.0/validated_linux_requirements.txt [--no-deps]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ dependencies:
2222

2323
- pip:
2424
# Required packages for AzureML execution, history, and data preparation.
25-
- azureml-widgets~=1.28.0
25+
- azureml-widgets~=1.29.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://automlresources-prod.azureedge.net/validated-requirements/1.28.0/validated_darwin_requirements.txt [--no-deps]
29+
- -r https://automlresources-prod.azureedge.net/validated-requirements/1.29.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.28.0 of the Azure ML SDK\")\n",
108+
"print(\"This notebook was created using version 1.29.0 of the Azure ML SDK\")\n",
109109
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
110110
]
111111
},

0 commit comments

Comments
 (0)