lale/lib/aif360/datasets.py
def fetch_bank_df(preprocess=False):
    """
    Fetch the `bank-marketing`_ dataset from OpenML and add `fairness_info`.

    It contains information from marketing campaigns of a Portuguise
    bank.  The prediction task is a binary classification on whether
    the client will subscribe a term deposit. Without preprocessing,
    the dataset has 45,211 rows and 16 columns. There is one protected
    attribute, age, and the disparate impact of 0.84. The data
    includes both categorical and numeric columns, with no missing
    values.

    .. _`bank-marketing`: https://www.openml.org/d/1461

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

      If True,
      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(
        "bank-marketing", "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().astype(np.float64)
    column_map = {
        "v1": "age",
        "v2": "job",
        "v3": "marital",
        "v4": "education",
        "v5": "default",
        "v6": "balance",
        "v7": "housing",
        "v8": "loan",
        "v9": "contact",
        "v10": "day",
        "v11": "month",
        "v12": "duration",
        "v13": "campaign",
        "v14": "pdays",
        "v15": "previous",
        "v16": "poutcome",
    }
    if preprocess:

        def map_col(col):
            if col.find("_") == -1:
                return column_map[col]
            prefix, suffix = col.split("_")
            return column_map[prefix] + "_" + suffix

        orig_X.columns = [map_col(col) for col in orig_X.columns]
        age = pd.Series(orig_X["age"] >= 25, dtype=np.float64)
        encoded_X = orig_X.assign(age=age)
        encoded_y = pd.Series(orig_y == 0, dtype=np.float64, name=orig_y.name)
        fairness_info = {
            "favorable_labels": [1],
            "protected_attributes": [
                {"feature": "age", "reference_group": [1]},
            ],
        }
        return encoded_X, encoded_y, fairness_info
    else:
        orig_X.columns = [column_map[col] for col in orig_X.columns]
        fairness_info = {
            "favorable_labels": [1],
            "protected_attributes": [
                {"feature": "age", "reference_group": [[25, 1000]]},
            ],
        }
        return orig_X, orig_y, fairness_info

    Fetch the `bank-marketing`_ dataset from OpenML and add `fairness_info`.

    It contains information from marketing campaigns of a Portuguise
    bank.  The prediction task is a binary classification on whether
    the client will subscribe a term deposit. Without preprocessing,
    the dataset has 45,211 rows and 16 columns. There is one protected
    attribute, age, and the disparate impact of 0.84. The data
    includes both categorical and numeric columns, with no missing
    values.

    .. _`bank-marketing`: https://www.openml.org/d/1461

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

      If True,
      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 `bank-marketing`_ dataset from OpenML and add `fairness_info`.
It contains information from marketing campaigns of a Portuguise
bank.  The prediction task is a binary classification on whether
the client will subscribe a term deposit. Without preprocessing,
the dataset has 45,211 rows and 16 columns. There is one protected
attribute, age, and the disparate impact of 0.84. The data
includes both categorical and numeric columns, with no missing
values.



Parameters

preprocess : boolean, optional, default False

If True,
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 ` bank - marketing ` _ dataset from OpenML and add ` fairness_info ` . It contains information from marketing campaigns of a Portuguise bank . The prediction task is a binary classification on whether the client will subscribe a term deposit . Without preprocessing the dataset has 45 211 rows and 16 columns . There is one protected attribute age and the disparate impact of 0 . 84 . The data includes both categorical and numeric columns with no missing values . Parameters preprocess : boolean optional default False If True 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_bank_df(preprocess=False):
    (train_X, train_y), (test_X, test_y) = lale.datasets.openml.fetch(
        "bank-marketing", "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().astype(np.float64)
    column_map = {
        "v1": "age",
        "v2": "job",
        "v3": "marital",
        "v4": "education",
        "v5": "default",
        "v6": "balance",
        "v7": "housing",
        "v8": "loan",
        "v9": "contact",
        "v10": "day",
        "v11": "month",
        "v12": "duration",
        "v13": "campaign",
        "v14": "pdays",
        "v15": "previous",
        "v16": "poutcome",
    }
    if preprocess:
        def map_col(col):
            if col.find("_") == -1:
                return column_map[col]
            prefix, suffix = col.split("_")
            return column_map[prefix] + "_" + suffix
        orig_X.columns = [map_col(col) for col in orig_X.columns]
        age = pd.Series(orig_X["age"] >= 25, dtype=np.float64)
        encoded_X = orig_X.assign(age=age)
        encoded_y = pd.Series(orig_y == 0, dtype=np.float64, name=orig_y.name)
        fairness_info = {
            "favorable_labels": [1],
            "protected_attributes": [
                {"feature": "age", "reference_group": [1]},
            ],
        }
        return encoded_X, encoded_y, fairness_info
    else:
        orig_X.columns = [column_map[col] for col in orig_X.columns]
        fairness_info = {
            "favorable_labels": [1],
            "protected_attributes": [
                {"feature": "age", "reference_group": [[25, 1000]]},
            ],
        }
        return orig_X, orig_y, fairness_info
def fetch_bank_df ( preprocess = False ) : ( train_X , train_y ) , ( test_X , test_y ) = lale . datasets . openml . fetch ( "bank-marketing" , "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 ( ) . astype ( np . float64 ) column_map = { "v1" : "age" , "v2" : "job" , "v3" : "marital" , "v4" : "education" , "v5" : "default" , "v6" : "balance" , "v7" : "housing" , "v8" : "loan" , "v9" : "contact" , "v10" : "day" , "v11" : "month" , "v12" : "duration" , "v13" : "campaign" , "v14" : "pdays" , "v15" : "previous" , "v16" : "poutcome" , } if preprocess : def map_col ( col ) : if col . find ( "_" ) == - 1 : return column_map [ col ] prefix , suffix = col . split ( "_" ) return column_map [ prefix ] + "_" + suffix orig_X . columns = [ map_col ( col ) for col in orig_X . columns ] age = pd . Series ( orig_X [ "age" ] >= 25 , dtype = np . float64 ) encoded_X = orig_X . assign ( age = age ) encoded_y = pd . Series ( orig_y == 0 , dtype = np . float64 , name = orig_y . name ) fairness_info = { "favorable_labels" : [ 1 ] , "protected_attributes" : [ { "feature" : "age" , "reference_group" : [ 1 ] } , ] , } return encoded_X , encoded_y , fairness_info else : orig_X . columns = [ column_map [ col ] for col in orig_X . columns ] fairness_info = { "favorable_labels" : [ 1 ] , "protected_attributes" : [ { "feature" : "age" , "reference_group" : [ [ 25 , 1000 ] ] } , ] , } return orig_X , orig_y , fairness_info
Fetch the `bank-marketing`_ dataset from OpenML and add `fairness_info`.
Fetch the ` bank - marketing ` _ dataset from OpenML and add ` fairness_info ` .
"""
    Fetch the `bank-marketing`_ dataset from OpenML and add `fairness_info`.

    It contains information from marketing campaigns of a Portuguise
    bank.  The prediction task is a binary classification on whether
    the client will subscribe a term deposit. Without preprocessing,
    the dataset has 45,211 rows and 16 columns. There is one protected
    attribute, age, and the disparate impact of 0.84. The data
    includes both categorical and numeric columns, with no missing
    values.

    .. _`bank-marketing`: https://www.openml.org/d/1461

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

      If True,
      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