|
188 | 188 | "The _Statistical Parity Difference (SPD)_ is the difference in the probability of prediction between the privileged and unprivileged groups. Typically:\n",
|
189 | 189 | "\n",
|
190 | 190 | "- $SPD=0$ means that the model is behaving fairly in regards of the selected attribute (e.g. race, gender)\n",
|
191 |
| - "- $-0.1<SPD<0.1$ means that the model is _reasonably fair_ and the score can be attributed to other factor, such as sample size.\n", |
| 191 | + "- Values between $-0.1<SPD<0.1$ mean that the model is _reasonably fair_ and the score can be attributed to other factors, such as sample size.\n", |
192 | 192 | "- An $SPD$ outside this range would be an indicator of an _unfair_ model relatively to the protected attributes.\n",
|
193 | 193 | " - A *negative* value of statistical parity difference indicates that the unprivileged group is at a disadvantage\n",
|
194 | 194 | " - A *positive* value indicates that the privileged group is at a disadvantage.\n",
|
195 | 195 | "\n",
|
196 | 196 | "The formal definition of $SPD$ is\n",
|
197 | 197 | "\n",
|
198 | 198 | "$$\n",
|
199 |
| - "SPD=P(\\hat{y}=1|\\mathcal{D}_u)-P(\\hat{y}=1|\\mathcal{D}_p)\n", |
| 199 | + "SPD=p(\\hat{y}=1|\\mathcal{D}_u)-p(\\hat{y}=1|\\mathcal{D}_p)\n", |
200 | 200 | "$$\n",
|
201 | 201 | "\n",
|
202 | 202 | "where $\\hat{y}=1$ is the favorable outcome and $\\mathcal{D}_u$, $\\mathcal{D}_p$ are respectively the privileged and unpriviledge group data.\n",
|
|
207 | 207 | },
|
208 | 208 | {
|
209 | 209 | "cell_type": "code",
|
210 |
| - "execution_count": 6, |
| 210 | + "execution_count": 4, |
211 | 211 | "id": "8bd3f51b",
|
212 | 212 | "metadata": {},
|
213 | 213 | "outputs": [
|
|
222 | 222 | "Name: income, dtype: int64"
|
223 | 223 | ]
|
224 | 224 | },
|
225 |
| - "execution_count": 6, |
| 225 | + "execution_count": 4, |
226 | 226 | "metadata": {},
|
227 | 227 | "output_type": "execute_result"
|
228 | 228 | }
|
|
234 | 234 | },
|
235 | 235 | {
|
236 | 236 | "cell_type": "code",
|
237 |
| - "execution_count": 7, |
| 237 | + "execution_count": 5, |
238 | 238 | "id": "9e8978f6",
|
239 | 239 | "metadata": {},
|
240 | 240 | "outputs": [
|
|
244 | 244 | "<AxesSubplot:xlabel='gender'>"
|
245 | 245 | ]
|
246 | 246 | },
|
247 |
| - "execution_count": 7, |
| 247 | + "execution_count": 5, |
248 | 248 | "metadata": {},
|
249 | 249 | "output_type": "execute_result"
|
250 | 250 | },
|
|
265 | 265 | },
|
266 | 266 | {
|
267 | 267 | "cell_type": "code",
|
268 |
| - "execution_count": 22, |
| 268 | + "execution_count": 7, |
269 | 269 | "id": "2b2c678a",
|
270 | 270 | "metadata": {},
|
271 | 271 | "outputs": [],
|
|
283 | 283 | },
|
284 | 284 | {
|
285 | 285 | "cell_type": "code",
|
286 |
| - "execution_count": 23, |
| 286 | + "execution_count": 8, |
287 | 287 | "id": "9e548018",
|
288 | 288 | "metadata": {},
|
289 | 289 | "outputs": [
|
|
301 | 301 | },
|
302 | 302 | {
|
303 | 303 | "cell_type": "markdown",
|
304 |
| - "id": "cd296c85", |
| 304 | + "id": "a13a2ac3", |
305 | 305 | "metadata": {},
|
306 | 306 | "source": [
|
307 | 307 | "We can see that the $SPD$ for this dataset is between the $[-0.1, 0.1]$ threshold, which classifies the model as _reasonably fair_."
|
|
312 | 312 | "id": "09bb7d45",
|
313 | 313 | "metadata": {},
|
314 | 314 | "source": [
|
315 |
| - "## Biased dataset" |
| 315 | + "### Biased dataset" |
316 | 316 | ]
|
317 | 317 | },
|
318 | 318 | {
|
319 | 319 | "cell_type": "code",
|
320 |
| - "execution_count": 10, |
| 320 | + "execution_count": 9, |
321 | 321 | "id": "63b953c9",
|
322 | 322 | "metadata": {},
|
323 | 323 | "outputs": [
|
|
332 | 332 | "Name: income, dtype: int64"
|
333 | 333 | ]
|
334 | 334 | },
|
335 |
| - "execution_count": 10, |
| 335 | + "execution_count": 9, |
336 | 336 | "metadata": {},
|
337 | 337 | "output_type": "execute_result"
|
338 | 338 | }
|
|
344 | 344 | },
|
345 | 345 | {
|
346 | 346 | "cell_type": "code",
|
347 |
| - "execution_count": 11, |
| 347 | + "execution_count": 10, |
348 | 348 | "id": "aed61b77",
|
349 | 349 | "metadata": {},
|
350 | 350 | "outputs": [
|
|
354 | 354 | "<AxesSubplot:xlabel='gender'>"
|
355 | 355 | ]
|
356 | 356 | },
|
357 |
| - "execution_count": 11, |
| 357 | + "execution_count": 10, |
358 | 358 | "metadata": {},
|
359 | 359 | "output_type": "execute_result"
|
360 | 360 | },
|
|
375 | 375 | },
|
376 | 376 | {
|
377 | 377 | "cell_type": "code",
|
378 |
| - "execution_count": 12, |
| 378 | + "execution_count": 11, |
379 | 379 | "id": "901e5720",
|
380 | 380 | "metadata": {},
|
381 | 381 | "outputs": [],
|
|
390 | 390 | },
|
391 | 391 | {
|
392 | 392 | "cell_type": "code",
|
393 |
| - "execution_count": 13, |
| 393 | + "execution_count": 12, |
394 | 394 | "id": "7be544a7",
|
395 | 395 | "metadata": {},
|
396 | 396 | "outputs": [
|
|
408 | 408 | },
|
409 | 409 | {
|
410 | 410 | "cell_type": "markdown",
|
411 |
| - "id": "719cba51", |
| 411 | + "id": "8e3f2bd4", |
412 | 412 | "metadata": {},
|
413 | 413 | "source": [
|
414 | 414 | "This dataset, as expected, is outside the $[-0.1, 0.1]$ threshold, which classifies the model as _unfair_.\n",
|
|
420 | 420 | "id": "de0affcf",
|
421 | 421 | "metadata": {},
|
422 | 422 | "source": [
|
423 |
| - "# Disparate impact ratio" |
| 423 | + "## Disparate impact ratio\n", |
| 424 | + "\n", |
| 425 | + "\n", |
| 426 | + "Similarly to the _Statistical Parity Difference_, the _Disparate Impact Ratio (DIR)_ measures imbalances in positive outcome predictions across privliged and unpriviliged groups.\n", |
| 427 | + "Instead of calculating the difference, this metric calculates the ration of such selection rates.Typically:\n", |
| 428 | + "\n", |
| 429 | + "- $DIR=1$ means that the model is fair with regards to the protected attribute.\n", |
| 430 | + "- $0.8<DIR<1.2$ means that the model is _reasonably fair_.\n", |
| 431 | + "\n", |
| 432 | + "The formal definition of the _Disparate Impact Ratio_ is:\n", |
| 433 | + "\n", |
| 434 | + "$$\n", |
| 435 | + "DIR=\\dfrac{p(\\hat{y}=1|\\mathcal{D}_u)}{p(\\hat{y}=1|\\mathcal{D}_p)}\n", |
| 436 | + "$$\n" |
424 | 437 | ]
|
425 | 438 | },
|
426 | 439 | {
|
427 | 440 | "cell_type": "code",
|
428 |
| - "execution_count": 14, |
| 441 | + "execution_count": 13, |
429 | 442 | "id": "949fae2f",
|
430 | 443 | "metadata": {},
|
431 | 444 | "outputs": [],
|
|
439 | 452 | },
|
440 | 453 | {
|
441 | 454 | "cell_type": "code",
|
442 |
| - "execution_count": 15, |
| 455 | + "execution_count": 14, |
443 | 456 | "id": "2e601762",
|
444 | 457 | "metadata": {},
|
445 | 458 | "outputs": [
|
|
455 | 468 | "print(score)"
|
456 | 469 | ]
|
457 | 470 | },
|
| 471 | + { |
| 472 | + "cell_type": "markdown", |
| 473 | + "id": "7dfc3077-0739-4b19-bfc3-9c16c70e048c", |
| 474 | + "metadata": {}, |
| 475 | + "source": [ |
| 476 | + "As with the $SPD$ we can see that the $DIR$ indicates a reasonably fair model (close to $1$) for the unbiased dataset." |
| 477 | + ] |
| 478 | + }, |
458 | 479 | {
|
459 | 480 | "cell_type": "code",
|
460 |
| - "execution_count": 16, |
| 481 | + "execution_count": 15, |
461 | 482 | "id": "3231326d",
|
462 | 483 | "metadata": {},
|
463 | 484 | "outputs": [],
|
|
469 | 490 | },
|
470 | 491 | {
|
471 | 492 | "cell_type": "code",
|
472 |
| - "execution_count": 17, |
| 493 | + "execution_count": 16, |
473 | 494 | "id": "4b88eec8",
|
474 | 495 | "metadata": {},
|
475 | 496 | "outputs": [
|
|
485 | 506 | "print(score)"
|
486 | 507 | ]
|
487 | 508 | },
|
| 509 | + { |
| 510 | + "cell_type": "markdown", |
| 511 | + "id": "5b7c07d4-c216-41dc-b259-df8fd6b4d064", |
| 512 | + "metadata": {}, |
| 513 | + "source": [ |
| 514 | + "And also, as expected, the $DIR$ indicates a biased model for the biased dataset." |
| 515 | + ] |
| 516 | + }, |
488 | 517 | {
|
489 | 518 | "cell_type": "markdown",
|
490 | 519 | "id": "7e9ca225",
|
|
0 commit comments