lale/lib/aif360/datasets.py
def fetch_adult_df(preprocess=False):
    """
    Fetch the `adult`_ dataset from OpenML and add `fairness_info`.
    It contains information about individuals from the 1994 U.S. census.
    The prediction task is a binary classification on whether the
    income of a person exceeds 50K a year. Without preprocessing,
    the dataset has 48,842 rows and 14 columns. There are two
    protected attributes, sex and race, and the disparate impact is
    0.23. The data includes both categorical and numeric columns, and
    has some missing values.

    .. _`adult`: https://www.openml.org/d/179

    Parameters
    ----------
    preprocess : boolean, optional, default False

      If True,
      impute missing values;
      encode protected attributes in X as 0 or 1 to indicate privileged groups;
      encode labels in y as 0 or 1 to indicate favorable outcomes;
      and apply one-hot encoding to any remaining features in X that
      are categorical and not protected attributes.

    Returns
    -------
    result : tuple

      - item 0: pandas Dataframe

          Features X, including both protected and non-protected attributes.

      - item 1: pandas Series

          Labels y.

      - item 3: fairness_info

          JSON meta-data following the format understood by fairness metrics
          and mitigation operators in `lale.lib.aif360`.
    """
    (train_X, train_y), (test_X, test_y) = lale.datasets.openml.fetch(
        "adult", "classification", astype="pandas", preprocess=preprocess
    )
    orig_X = pd.concat([train_X, test_X]).sort_index()
    orig_y = pd.concat([train_y, test_y]).sort_index()
    if preprocess:
        sex = pd.Series(orig_X["sex_Male"] == 1, dtype=np.float64)
        race = pd.Series(orig_X["race_White"] == 1, dtype=np.float64)
        dropped_X = orig_X.drop(
            labels=[
                "race_Amer-Indian-Eskimo",
                "race_Asian-Pac-Islander",
                "race_Black",
                "race_Other",
                "race_White",
                "sex_Female",
                "sex_Male",
            ],
            axis=1,
        )
        encoded_X = dropped_X.assign(sex=sex, race=race)
        assert not encoded_X.isna().any().any()
        assert not orig_y.isna().any().any()
        fairness_info = {
            "favorable_labels": [1],
            "protected_attributes": [
                {"feature": "sex", "reference_group": [1]},
                {"feature": "race", "reference_group": [1]},
            ],
        }
        return encoded_X, orig_y, fairness_info
    else:
        fairness_info = {
            "favorable_labels": [">50K"],
            "protected_attributes": [
                {"feature": "race", "reference_group": ["White"]},
                {"feature": "sex", "reference_group": ["Male"]},
            ],
        }
        return orig_X, orig_y, fairness_info

    Fetch the `adult`_ dataset from OpenML and add `fairness_info`.
    It contains information about individuals from the 1994 U.S. census.
    The prediction task is a binary classification on whether the
    income of a person exceeds 50K a year. Without preprocessing,
    the dataset has 48,842 rows and 14 columns. There are two
    protected attributes, sex and race, and the disparate impact is
    0.23. The data includes both categorical and numeric columns, and
    has some missing values.

    .. _`adult`: https://www.openml.org/d/179

    Parameters
    ----------
    preprocess : boolean, optional, default False

      If True,
      impute missing values;
      encode protected attributes in X as 0 or 1 to indicate privileged groups;
      encode labels in y as 0 or 1 to indicate favorable outcomes;
      and apply one-hot encoding to any remaining features in X that
      are categorical and not protected attributes.

    Returns
    -------
    result : tuple

      - item 0: pandas Dataframe

          Features X, including both protected and non-protected attributes.

      - item 1: pandas Series

          Labels y.

      - item 3: fairness_info

          JSON meta-data following the format understood by fairness metrics
          and mitigation operators in `lale.lib.aif360`.
    
Fetch the `adult`_ dataset from OpenML and add `fairness_info`.
It contains information about individuals from the 1994 U.S. census.
The prediction task is a binary classification on whether the
income of a person exceeds 50K a year. Without preprocessing,
the dataset has 48,842 rows and 14 columns. There are two
protected attributes, sex and race, and the disparate impact is
0.23. The data includes both categorical and numeric columns, and
has some missing values.



Parameters

preprocess : boolean, optional, default False

If True,
impute missing values;
encode protected attributes in X as 0 or 1 to indicate privileged groups;
encode labels in y as 0 or 1 to indicate favorable outcomes;
and apply one-hot encoding to any remaining features in X that
are categorical and not protected attributes.

Returns

result : tuple

item 0: pandas Dataframe

Features X, including both protected and non-protected attributes.

item 1: pandas Series

Labels y.



JSON meta-data following the format understood by fairness metrics
and mitigation operators in `lale.lib.aif360`.
Fetch the ` adult ` _ dataset from OpenML and add ` fairness_info ` . It contains information about individuals from the 1994 U . S . census . The prediction task is a binary classification on whether the income of a person exceeds 50K a year . Without preprocessing the dataset has 48 842 rows and 14 columns . There are two protected attributes sex and race and the disparate impact is 0 . 23 . The data includes both categorical and numeric columns and has some missing values . Parameters preprocess : boolean optional default False If True impute missing values ; encode protected attributes in X as 0 or 1 to indicate privileged groups ; encode labels in y as 0 or 1 to indicate favorable outcomes ; and apply one - hot encoding to any remaining features in X that are categorical and not protected attributes . Returns result : tuple item 0 : pandas Dataframe Features X including both protected and non - protected attributes . item 1 : pandas Series Labels y . JSON meta - data following the format understood by fairness metrics and mitigation operators in ` lale . lib . aif360 ` .
def fetch_adult_df(preprocess=False):
    (train_X, train_y), (test_X, test_y) = lale.datasets.openml.fetch(
        "adult", "classification", astype="pandas", preprocess=preprocess
    )
    orig_X = pd.concat([train_X, test_X]).sort_index()
    orig_y = pd.concat([train_y, test_y]).sort_index()
    if preprocess:
        sex = pd.Series(orig_X["sex_Male"] == 1, dtype=np.float64)
        race = pd.Series(orig_X["race_White"] == 1, dtype=np.float64)
        dropped_X = orig_X.drop(
            labels=[
                "race_Amer-Indian-Eskimo",
                "race_Asian-Pac-Islander",
                "race_Black",
                "race_Other",
                "race_White",
                "sex_Female",
                "sex_Male",
            ],
            axis=1,
        )
        encoded_X = dropped_X.assign(sex=sex, race=race)
        assert not encoded_X.isna().any().any()
        assert not orig_y.isna().any().any()
        fairness_info = {
            "favorable_labels": [1],
            "protected_attributes": [
                {"feature": "sex", "reference_group": [1]},
                {"feature": "race", "reference_group": [1]},
            ],
        }
        return encoded_X, orig_y, fairness_info
    else:
        fairness_info = {
            "favorable_labels": [">50K"],
            "protected_attributes": [
                {"feature": "race", "reference_group": ["White"]},
                {"feature": "sex", "reference_group": ["Male"]},
            ],
        }
        return orig_X, orig_y, fairness_info
def fetch_adult_df ( preprocess = False ) : ( train_X , train_y ) , ( test_X , test_y ) = lale . datasets . openml . fetch ( "adult" , "classification" , astype = "pandas" , preprocess = preprocess ) orig_X = pd . concat ( [ train_X , test_X ] ) . sort_index ( ) orig_y = pd . concat ( [ train_y , test_y ] ) . sort_index ( ) if preprocess : sex = pd . Series ( orig_X [ "sex_Male" ] == 1 , dtype = np . float64 ) race = pd . Series ( orig_X [ "race_White" ] == 1 , dtype = np . float64 ) dropped_X = orig_X . drop ( labels = [ "race_Amer-Indian-Eskimo" , "race_Asian-Pac-Islander" , "race_Black" , "race_Other" , "race_White" , "sex_Female" , "sex_Male" , ] , axis = 1 , ) encoded_X = dropped_X . assign ( sex = sex , race = race ) assert not encoded_X . isna ( ) . any ( ) . any ( ) assert not orig_y . isna ( ) . any ( ) . any ( ) fairness_info = { "favorable_labels" : [ 1 ] , "protected_attributes" : [ { "feature" : "sex" , "reference_group" : [ 1 ] } , { "feature" : "race" , "reference_group" : [ 1 ] } , ] , } return encoded_X , orig_y , fairness_info else : fairness_info = { "favorable_labels" : [ ">50K" ] , "protected_attributes" : [ { "feature" : "race" , "reference_group" : [ "White" ] } , { "feature" : "sex" , "reference_group" : [ "Male" ] } , ] , } return orig_X , orig_y , fairness_info
Fetch the `adult`_ dataset from OpenML and add `fairness_info`.
Fetch the ` adult ` _ dataset from OpenML and add ` fairness_info ` .
"""
    Fetch the `adult`_ dataset from OpenML and add `fairness_info`.
    It contains information about individuals from the 1994 U.S. census.
    The prediction task is a binary classification on whether the
    income of a person exceeds 50K a year. Without preprocessing,
    the dataset has 48,842 rows and 14 columns. There are two
    protected attributes, sex and race, and the disparate impact is
    0.23. The data includes both categorical and numeric columns, and
    has some missing values.

    .. _`adult`: https://www.openml.org/d/179

    Parameters
    ----------
    preprocess : boolean, optional, default False

      If True,
      impute missing values;
      encode protected attributes in X as 0 or 1 to indicate privileged groups;
      encode labels in y as 0 or 1 to indicate favorable outcomes;
      and apply one-hot encoding to any remaining features in X that
      are categorical and not protected attributes.

    Returns
    -------
    result : tuple

      - item 0: pandas Dataframe

          Features X, including both protected and non-protected attributes.

      - item 1: pandas Series

          Labels y.

      - item 3: fairness_info

          JSON meta-data following the format understood by fairness metrics
          and mitigation operators in `lale.lib.aif360`.
    """
preprocess