-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
3,448 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import fairbench as fb | ||
import torch | ||
|
||
report = fb.multireport( | ||
predictions=torch.randint(2, (2,)), | ||
labels=torch.randint(2, (2,)), | ||
sensetive=fb.Fork(fb.categories @ ["m", "f"]), | ||
metrics=[fb.metrics.accuracy, fb.metrics.pr, fb.metrics.fpr, fb.metrics.fnr], | ||
) | ||
print(report) | ||
stamps = fb.combine( | ||
fb.stamps.prule(report), fb.stamps.accuracy(report), fb.stamps.four_fifths(report) | ||
) | ||
print(fb.stamps.available()) | ||
print(stamps.symbols) | ||
fb.modelcards.tohtml(stamps, file="model_card.html", show=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,12 @@ | ||
import pygrank as pg | ||
import fairbench as fb | ||
|
||
"""load data and set sensitive attribute""" | ||
_, graph, communities = next(pg.load_datasets_multiple_communities(["highschool"])) | ||
train, test = pg.split(pg.to_signal(graph, communities[0]), 0.5) | ||
sensitive_signal = pg.to_signal(graph, communities[1]) | ||
labels = test.filter(exclude=train) | ||
sensitive = fb.Fork(gender=fb.categories@sensitive_signal.filter(exclude=train)) | ||
# testing heterogeneous setting | ||
test, y, yhat = fb.demos.adult(predict="probabilities") | ||
s = fb.Fork(fb.categories @ test[9]) # test[8] is a pandas column with race values | ||
|
||
"""create report for pagerank""" | ||
algorithm = pg.PageRank(alpha=0.85) | ||
scores = algorithm(train).filter(exclude=train) | ||
report = fb.multireport(labels=labels, scores=scores, sensitive=sensitive) | ||
|
||
"""create report for locally fair pagerank""" | ||
fair_algorithm = pg.LFPR(alpha=0.85, redistributor="original") | ||
fair_scores = fair_algorithm(train, sensitive=sensitive_signal).filter(exclude=train) | ||
fair_report = fb.multireport(labels=labels, scores=fair_scores, sensitive=sensitive) | ||
|
||
"""combine both reports into one and get the auc perspective""" | ||
fork = fb.Fork(ppr=report, lfpr=fair_report) | ||
fb.describe(fork.auc) | ||
report = fb.multireport( | ||
scores=yhat, predictions=(yhat > 0.5), labels=y, sensitive=s, top=50 | ||
) | ||
# report2 = fb.unireport(predictions=(yhat > 0.5), labels=y, sensitive=s, top=50) | ||
# report = fb.combine(report, report2) | ||
# fb.interactive(report) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.