Skip to content

Commit a2d20b0

Browse files
authored
Merge pull request Azure#1493 from Azure/release_update/Release-98
update samples from Release-98 as a part of SDK release
2 parents 700ab2d + 8180ceb commit a2d20b0

19 files changed

+71
-484
lines changed

contrib/fairness/fairlearn-azureml-mitigation.ipynb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@
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.6.2` (pre-v0.5.0 will work with minor modifications)\n",
49+
"* `fairlearn==0.4.6` (v0.5.0 will work with minor modifications)\n",
5050
"* `joblib`\n",
5151
"* `liac-arff`\n",
52-
"* `raiwidgets==0.4.0`\n",
5352
"\n",
5453
"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:"
5554
]
@@ -86,7 +85,7 @@
8685
"outputs": [],
8786
"source": [
8887
"from fairlearn.reductions import GridSearch, DemographicParity, ErrorRate\n",
89-
"from raiwidgets import FairnessDashboard\n",
88+
"from fairlearn.widget import FairlearnDashboard\n",
9089
"\n",
9190
"from sklearn.compose import ColumnTransformer\n",
9291
"from sklearn.impute import SimpleImputer\n",
@@ -257,9 +256,9 @@
257256
"metadata": {},
258257
"outputs": [],
259258
"source": [
260-
"FairnessDashboard(sensitive_features=A_test,\n",
261-
" y_true=y_test,\n",
262-
" y_pred={\"unmitigated\": unmitigated_predictor.predict(X_test)})"
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)})"
263262
]
264263
},
265264
{
@@ -312,8 +311,8 @@
312311
"sweep.fit(X_train, y_train,\n",
313312
" sensitive_features=A_train.sex)\n",
314313
"\n",
315-
"# For Fairlearn pre-v0.5.0, need sweep._predictors\n",
316-
"predictors = sweep.predictors_"
314+
"# For Fairlearn v0.5.0, need sweep.predictors_\n",
315+
"predictors = sweep._predictors"
317316
]
318317
},
319318
{
@@ -330,14 +329,16 @@
330329
"outputs": [],
331330
"source": [
332331
"errors, disparities = [], []\n",
333-
"for predictor in predictors:\n",
332+
"for m in predictors:\n",
333+
" classifier = lambda X: m.predict(X)\n",
334+
" \n",
334335
" error = ErrorRate()\n",
335336
" error.load_data(X_train, pd.Series(y_train), sensitive_features=A_train.sex)\n",
336337
" disparity = DemographicParity()\n",
337338
" disparity.load_data(X_train, pd.Series(y_train), sensitive_features=A_train.sex)\n",
338339
" \n",
339-
" errors.append(error.gamma(predictor.predict)[0])\n",
340-
" disparities.append(disparity.gamma(predictor.predict).max())\n",
340+
" errors.append(error.gamma(classifier)[0])\n",
341+
" disparities.append(disparity.gamma(classifier).max())\n",
341342
" \n",
342343
"all_results = pd.DataFrame( {\"predictor\": predictors, \"error\": errors, \"disparity\": disparities})\n",
343344
"\n",
@@ -386,9 +387,10 @@
386387
"metadata": {},
387388
"outputs": [],
388389
"source": [
389-
"FairnessDashboard(sensitive_features=A_test, \n",
390-
" y_true=y_test.tolist(),\n",
391-
" y_pred=predictions_dominant)"
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)"
392394
]
393395
},
394396
{
@@ -407,7 +409,7 @@
407409
"<a id=\"AzureUpload\"></a>\n",
408410
"## Uploading a Fairness Dashboard to Azure\n",
409411
"\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",
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",
411413
"1. Register the dominant models\n",
412414
"1. Precompute all the required metrics\n",
413415
"1. Upload to Azure\n",

contrib/fairness/fairlearn-azureml-mitigation.yml

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

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 Fairness Dashboard](#LocalDashboard)\n",
33+
"1. [Using the Fairlearn 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,10 +48,9 @@
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.6.2` (also works for pre-v0.5.0 with slight modifications)\n",
51+
"* `fairlearn==0.4.6` (should also work with v0.5.0)\n",
5252
"* `joblib`\n",
5353
"* `liac-arff`\n",
54-
"* `raiwidgets==0.4.0`\n",
5554
"\n",
5655
"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:"
5756
]
@@ -389,11 +388,12 @@
389388
"metadata": {},
390389
"outputs": [],
391390
"source": [
392-
"from raiwidgets import FairnessDashboard\n",
391+
"from fairlearn.widget import FairlearnDashboard\n",
393392
"\n",
394-
"FairnessDashboard(sensitive_features=A_test, \n",
395-
" y_true=y_test.tolist(),\n",
396-
" y_pred=ys_pred)"
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)"
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 `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",
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",
407407
"1. Precompute all the required metrics\n",
408408
"1. Upload to Azure\n",
409409
"\n",

contrib/fairness/upload-fairness-dashboard.yml

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

0 commit comments

Comments
 (0)