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

    It contains data gathered from applicants to public schools in
    Ljubljana, Slovenia during a competitive time period.
    Without preprocessing, the dataset has
    12960 rows and 8 columns.  There is one protected attribute, parents, and the
    disparate impact is 0.46.  The data has categorical columns (with
    numeric ones if preprocessing is applied), with no missing values.

    .. _`nursery`: https://www.openml.org/d/26

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

      If True,
      encode protected attributes in X as 0 or 1 to indicate privileged groups
      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(
        "nursery", "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:
        parents = pd.Series(orig_X["parents_usual"] == 0, dtype=np.float64)
        dropped_X = orig_X.drop(
            labels=[
                "parents_great_pret",
                "parents_pretentious",
                "parents_usual",
            ],
            axis=1,
        )
        encoded_X = dropped_X.assign(parents=parents)
        # orig_y == 3 corresponds to "spec_prior"
        encoded_y = pd.Series((orig_y == 3), dtype=np.float64)
        fairness_info = {
            "favorable_labels": [1],
            "protected_attributes": [{"feature": "parents", "reference_group": [1]}],
        }
        return encoded_X, encoded_y, fairness_info
    else:
        fairness_info = {
            "favorable_labels": ["spec_prior"],
            "protected_attributes": [
                {
                    "feature": "parents",
                    "reference_group": ["great_pret", "pretentious"],
                }
            ],
        }
        return orig_X, orig_y, fairness_info

    Fetch the `nursery`_ dataset from OpenML and add `fairness_info`.

    It contains data gathered from applicants to public schools in
    Ljubljana, Slovenia during a competitive time period.
    Without preprocessing, the dataset has
    12960 rows and 8 columns.  There is one protected attribute, parents, and the
    disparate impact is 0.46.  The data has categorical columns (with
    numeric ones if preprocessing is applied), with no missing values.

    .. _`nursery`: https://www.openml.org/d/26

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

      If True,
      encode protected attributes in X as 0 or 1 to indicate privileged groups
      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 `nursery`_ dataset from OpenML and add `fairness_info`.
It contains data gathered from applicants to public schools in
Ljubljana, Slovenia during a competitive time period.
Without preprocessing, the dataset has
12960 rows and 8 columns.  There is one protected attribute, parents, and the
disparate impact is 0.46.  The data has categorical columns (with
numeric ones if preprocessing is applied), 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
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 ` nursery ` _ dataset from OpenML and add ` fairness_info ` . It contains data gathered from applicants to public schools in Ljubljana Slovenia during a competitive time period . Without preprocessing the dataset has 12960 rows and 8 columns . There is one protected attribute parents and the disparate impact is 0 . 46 . The data has categorical columns ( with numeric ones if preprocessing is applied ) 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 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_nursery_df(preprocess=False):
    (train_X, train_y), (test_X, test_y) = lale.datasets.openml.fetch(
        "nursery", "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:
        parents = pd.Series(orig_X["parents_usual"] == 0, dtype=np.float64)
        dropped_X = orig_X.drop(
            labels=[
                "parents_great_pret",
                "parents_pretentious",
                "parents_usual",
            ],
            axis=1,
        )
        encoded_X = dropped_X.assign(parents=parents)
        encoded_y = pd.Series((orig_y == 3), dtype=np.float64)
        fairness_info = {
            "favorable_labels": [1],
            "protected_attributes": [{"feature": "parents", "reference_group": [1]}],
        }
        return encoded_X, encoded_y, fairness_info
    else:
        fairness_info = {
            "favorable_labels": ["spec_prior"],
            "protected_attributes": [
                {
                    "feature": "parents",
                    "reference_group": ["great_pret", "pretentious"],
                }
            ],
        }
        return orig_X, orig_y, fairness_info
def fetch_nursery_df ( preprocess = False ) : ( train_X , train_y ) , ( test_X , test_y ) = lale . datasets . openml . fetch ( "nursery" , "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 : parents = pd . Series ( orig_X [ "parents_usual" ] == 0 , dtype = np . float64 ) dropped_X = orig_X . drop ( labels = [ "parents_great_pret" , "parents_pretentious" , "parents_usual" , ] , axis = 1 , ) encoded_X = dropped_X . assign ( parents = parents ) encoded_y = pd . Series ( ( orig_y == 3 ) , dtype = np . float64 ) fairness_info = { "favorable_labels" : [ 1 ] , "protected_attributes" : [ { "feature" : "parents" , "reference_group" : [ 1 ] } ] , } return encoded_X , encoded_y , fairness_info else : fairness_info = { "favorable_labels" : [ "spec_prior" ] , "protected_attributes" : [ { "feature" : "parents" , "reference_group" : [ "great_pret" , "pretentious" ] , } ] , } return orig_X , orig_y , fairness_info
Fetch the `nursery`_ dataset from OpenML and add `fairness_info`.
Fetch the ` nursery ` _ dataset from OpenML and add ` fairness_info ` .
"""
    Fetch the `nursery`_ dataset from OpenML and add `fairness_info`.

    It contains data gathered from applicants to public schools in
    Ljubljana, Slovenia during a competitive time period.
    Without preprocessing, the dataset has
    12960 rows and 8 columns.  There is one protected attribute, parents, and the
    disparate impact is 0.46.  The data has categorical columns (with
    numeric ones if preprocessing is applied), with no missing values.

    .. _`nursery`: https://www.openml.org/d/26

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

      If True,
      encode protected attributes in X as 0 or 1 to indicate privileged groups
      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`.
    """ # orig_y == 3 corresponds to "spec_prior"
preprocess