|
46 | 46 | "Please see the [configuration notebook](../../configuration.ipynb) for information about creating one, if required.\n",
|
47 | 47 | "This notebook also requires the following packages:\n",
|
48 | 48 | "* `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", |
50 | 50 | "* `joblib`\n",
|
51 | 51 | "* `liac-arff`\n",
|
52 |
| - "* `raiwidgets==0.4.0`\n", |
53 | 52 | "\n",
|
54 | 53 | "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:"
|
55 | 54 | ]
|
|
86 | 85 | "outputs": [],
|
87 | 86 | "source": [
|
88 | 87 | "from fairlearn.reductions import GridSearch, DemographicParity, ErrorRate\n",
|
89 |
| - "from raiwidgets import FairnessDashboard\n", |
| 88 | + "from fairlearn.widget import FairlearnDashboard\n", |
90 | 89 | "\n",
|
91 | 90 | "from sklearn.compose import ColumnTransformer\n",
|
92 | 91 | "from sklearn.impute import SimpleImputer\n",
|
|
257 | 256 | "metadata": {},
|
258 | 257 | "outputs": [],
|
259 | 258 | "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)})" |
263 | 262 | ]
|
264 | 263 | },
|
265 | 264 | {
|
|
312 | 311 | "sweep.fit(X_train, y_train,\n",
|
313 | 312 | " sensitive_features=A_train.sex)\n",
|
314 | 313 | "\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" |
317 | 316 | ]
|
318 | 317 | },
|
319 | 318 | {
|
|
330 | 329 | "outputs": [],
|
331 | 330 | "source": [
|
332 | 331 | "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", |
334 | 335 | " error = ErrorRate()\n",
|
335 | 336 | " error.load_data(X_train, pd.Series(y_train), sensitive_features=A_train.sex)\n",
|
336 | 337 | " disparity = DemographicParity()\n",
|
337 | 338 | " disparity.load_data(X_train, pd.Series(y_train), sensitive_features=A_train.sex)\n",
|
338 | 339 | " \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", |
341 | 342 | " \n",
|
342 | 343 | "all_results = pd.DataFrame( {\"predictor\": predictors, \"error\": errors, \"disparity\": disparities})\n",
|
343 | 344 | "\n",
|
|
386 | 387 | "metadata": {},
|
387 | 388 | "outputs": [],
|
388 | 389 | "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)" |
392 | 394 | ]
|
393 | 395 | },
|
394 | 396 | {
|
|
407 | 409 | "<a id=\"AzureUpload\"></a>\n",
|
408 | 410 | "## Uploading a Fairness Dashboard to Azure\n",
|
409 | 411 | "\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", |
411 | 413 | "1. Register the dominant models\n",
|
412 | 414 | "1. Precompute all the required metrics\n",
|
413 | 415 | "1. Upload to Azure\n",
|
|
0 commit comments