Aequitas API

src.aequitas.group

class src.aequitas.group.Group[source]
get_crosstabs(df, score_thresholds=None, model_id=1, attr_cols=None)[source]

Creates univariate groups and calculates group metrics.

Parameters:
  • df – a dataframe containing the following required columns [score, label_value]
  • score_thresholds – a dictionary { ‘rank_abs’:[] , ‘rank_pct’:[], ‘score’:[] }
  • model_id
Returns:

get_group_functions()[source]
Returns:

src.aequitas.bias

class src.aequitas.bias.Bias(key_columns=None, input_group_metrics=None, fill_divbyzero=None)[source]
get_disparity_major_group(df, key_columns=None, input_group_metrics=None, fill_divbyzero=None)[source]
Calculates the bias (disparity) metrics for the predefined list of group metrics using the majority group within each attribute as the reference group (denominator)
Parameters:df – the returning dataframe from the group.get_crosstabs
Returns:a dataframe with the bias metrics as new columns and the ref group, it must have the same number of rows as the input dataframe
get_disparity_min_metric(df, key_columns=None, input_group_metrics=None, fill_divbyzero=None)[source]
Calculates several ratios using the group metrics value and dividing by the minimum group metric value among all groups defined by each attribute
Parameters:
  • df – the resulting dataframe from the group get_crosstabs
  • input_group_metrics – the columns list corresponding to the group metrics for each

we want to calculate the Disparity values :return: a dataframe

get_disparity_predefined_groups(df, ref_groups_dict, key_columns=None, input_group_metrics=None, fill_divbyzero=None)[source]
Calculates the bias (disparity) metrics for the predefined list of input group metrics using a predefined reference group value for each attribute which is passed using ref_groups_dict ({‘attr1’:’val1’, ‘attr2’:’val2’})
Parameters:
  • df – the output dataframe of the group.get_crosstabs
  • ref_groups_dict – a dictionary {attribute_name:attribute_value, …}
  • key_columns – optional, the key columns to use on joins
  • input_group_metrics – optional, the group metrics to be used for creating the new

disparity metrics :param fill_divbyzero: optional, fill value to use when divided by zero :return: a dataframe with same number of rows as the input but with additional disparity metrics columns and ref_group_values

src.aequitas.fairness

class src.aequitas.fairness.Fairness(fair_eval=None, tau=None, fair_measures_depend=None, type_parity_depend=None, high_level_fairness_depend=None)[source]
fill_groupby_attribute_fairness(groupby_obj, key_columns, group_attribute_df, measures)[source]
Parameters:
  • groupby_obj
  • key_columns
  • group_attribute_df
  • measures
Returns:

get_group_attribute_fairness(group_value_df, fair_measures_requested=None)[source]
Parameters:group_value_df – the output dataframe of the get_group_value_fairness()
Returns:a new dataframe at the group_attribute level (no group_values) with fairness

measures at the group_attribute level. Checks for the min (False) across the groups defined by the group_attribute. IF the minimum is False then all group_attribute is false for the given fairness measure.

get_group_value_fairness(bias_df, tau=None, fair_measures_requested=None)[source]
Calculates the fairness measures defined in the fair_measures dictionary and adds them as columns to the input bias_df
Parameters:
  • bias_df – the output dataframe from the bias/disparities calculations
  • fair_eval – (optional) see __init__()
  • tau – (optional) see __init__()
  • fair_measures – (optional) see __init__()
Returns:

the input bias_df dataframe with additional columns for each of the fairness

measures defined in the fair_measures dictionary

get_overall_fairness(group_attribute_df)[source]
Calculates overall fairness regardless of the group_attributes. It searches for unfairness across group_attributes and outputs fairness if all group_attributes are fair
Parameters:group_attribute_df – the output df of the get_group_attributes_fairness
Returns:dictionary with overall unsupervised/supervised fairness and fairness in general

src.aequitas.preprocessing

src.aequitas.preprocessing.check_required_cols(df, required_cols)[source]
Parameters:
  • df
  • model_cols
Returns:

src.aequitas.preprocessing.discretize(df, target_cols)[source]
Parameters:
  • df
  • target_cols
Returns:

src.aequitas.preprocessing.get_attr_cols(df, non_attr_cols)[source]
Parameters:
  • df
  • non_attr_cols
Returns:

src.aequitas.preprocessing.preprocess_input_df(df, required_cols=None)[source]
Parameters:
  • df
  • non_attr_cols
Returns: