holisticai.bias.mitigation.FairTopK#

class holisticai.bias.mitigation.FairTopK(*args, **kargs)[source]#

Fair Top K bias mitigation [1] can be used for Recommender Systems. The strategy extends group fairness definition using the standard notion of protected groups and is based on ensuring that the proportion of protected candidates in every prefix of the top-k ranking.

Parameters

top_nint

The total number of elements.

pfloat

The proportion of protected candidates in the top-k ranking.

alphafloat

The significance level.

query_colstr

The name of the column in data that contains query ids.

doc_colstr

The name of the column in data that contains document ids.

group_colstr

The name of the column in data that contains protected attribute.

score_colstr

The name of the column in data that contains judgment values.

Examples

>>> from holisticai.bias.mitigation import FairTopK
>>> mitigator = FairTopK(**params)
>>> new_rankings = mitigator.transform(rankings)

References

is_fair(ranking)[source]#

Checks if the ranking is fair for the given parameters

Parameters

ranking: list

The ranking to be checked (list of Resultinfo)

Returns

bool

True if the ranking is fair, False otherwise.

transform(rankings, p_attr=None)[source]#

Apply transform to prediction scores.

Parameters

rankingsDataFrame

Predicted matrix scores (nb_examples*top_n, 3) [query_id, doc_id, scores]

p_attr: matrix-like

Item groups (nb_examples, 3) [query_id, doc_id, protected]

Returns

DataFrame

The re-ranked dataframe.

transform_ranking(ranking)[source]#

Applies FA*IR re-ranking to the input ranking using an adjusted mtable

Parameters

ranking: list

The ranking to be re-ranked (list of FairScoreDoc)

Returns

DataFrame

The re-ranked dataframe.