lale.lib.aif360 package

Submodules

Module contents

Scikit-learn compatible wrappers for several operators and metrics from AIF360 along with schemas to enable hyperparameter tuning, as well as functions for fetching fairness dataset.

All operators and metrics in the Lale wrappers for AIF360 take two arguments, favorable_labels and protected_attributes, collectively referred to as fairness info. For example, the following code indicates that the reference group comprises male values in the personal_status attribute as well as values from 26 to 1000 in the age attribute.

creditg_fairness_info = {
    "favorable_labels": ["good"],
    "protected_attributes": [
        {
            "feature": "personal_status",
            "reference_group": [
                "male div/sep", "male mar/wid", "male single",
            ],
        },
        {"feature": "age", "reference_group": [[26, 1000]]},
    ],
}

See the following notebooks for more detailed examples:

Pre-Estimator Mitigation Operators:

Post-Estimator Mitigation Operators:

Mitigator Patterns:

AIF360 provides three kinds of fairness mitigators, illustrated in the following picture. Pre-estimator mitigators transform the data before it gets to an estimator; in-estimator mitigators include their own estimator; and post-estimator mitigators transform predictions after those come back from an estimator.

../_images/fairness_patterns.png

In the picture, italics indicate parameters of the pattern. For example, consider the following code:

pipeline = LFR(
    **fairness_info,
    preparation=(
        (Project(columns={"type": "string"}) >> OneHotEncoder(handle_unknown="ignore"))
        & Project(columns={"type": "number"})
    )
    >> ConcatFeatures
) >> LogisticRegression(max_iter=1000)

In this example, the mitigator is LFR (which is pre-estimator), the estimator is LogisticRegression, and the preparation is a sub-pipeline that one-hot-encodes strings. If all features of the data are numerical, then the preparation can be omitted. Internally, the LFR higher-order operator uses two auxiliary operators, Redacting and ProtectedAttributesEncoder. Redacting sets protected attributes to a constant to prevent them from directly influencing fairness-agnostic data preparation or estimators. And the ProtectedAttributesEncoder encodes protected attributes and labels as zero or one to simplify the task for the mitigator.