(df)
return df
The custom pre-processing function is adapted from
    https://github.com/fair-preprocessing/nips2017/blob/master/compas/code/Generate_Compas_Data.ipynb
The custom pre-processing function is adapted from
    https://github.com/fair-preprocessing/nips2017/blob/master/compas/code/Generate_Compas_Data.ipynb
The custom pre - processing function is adapted from https : // github . com / fair - preprocessing / nips2017 / blob / master / compas / code / Generate_Compas_Data . ipynb
def _perform_custom_preprocessing(df):
    """The custom pre-processing function is adapted from
    https://github.com/fair-preprocessing/nips2017/blob/master/compas/code/Generate_Compas_Data.ipynb
    """

    df = df[
        [
            "age",
            "c_charge_degree",
            "race",
            "age_cat",
            "score_text",
            "sex",
            "priors_count",
            "days_b_screening_arrest",
            "decile_score",
            "is_recid",
            "two_year_recid",
            "c_jail_in",
            "c_jail_out",
        ]
    ]

    # Indices of data samples to keep
    ix = df["days_b_screening_arrest"] <= 30
    ix = (df["days_b_screening_arrest"] >= -30) & ix
    ix = (df["is_recid"] != -1) & ix
    ix = (df["c_charge_degree"] != "O") & ix
    ix = (df["score_text"] != "N/A") & ix
    df = df.loc[ix, :]
    df["length_of_stay"] = (
        pd.to_datetime(df["c_jail_out"]) - pd.to_datetime(df["c_jail_in"])
    ).apply(lambda x: x.days)

    # Restrict races to African-American and Caucasian
    dfcut = df.loc[
        ~df["race"].isin(["Native American", "Hispanic", "Asian", "Other"]), :
    ]

    # Restrict the features to use
    dfcutQ = dfcut[
        [
            "sex",
            "race",
            "age_cat",
            "c_charge_degree",
            "score_text",
            "priors_count",
            "is_recid",
            "two_year_recid",
            "length_of_stay",
        ]
    ].copy()

    # Quantize priors count between 0, 1-3, and >3
    def quantizePrior(x):
        if x <= 0:
            return "0"
        elif 1 <= x <= 3:
            return "1 to 3"
        else:
            return "More than 3"

    # Quantize length of stay
    def quantizeLOS(x):
        if x <= 7:
            return "<week"
        if 8 < x <= 93:
            return "<3months"
        else:
            return ">3 months"

    # Quantize length of stay
    def adjustAge(x):
        if x == "25 - 45":
            return "25 to 45"
        else:
            return x

    # Quantize score_text to MediumHigh
    def quantizeScore(x):
        if (x == "High") | (x == "Medium"):
            return "MediumHigh"
        else:
            return x

    def group_race(x):
        if x == "Caucasian":
            return 1.0
        else:
            return 0.0

    dfcutQ["priors_count"] = dfcutQ["priors_count"].apply(lambda x: quantizePrior(x))
    dfcutQ["length_of_stay"] = dfcutQ["length_of_stay"].apply(lambda x: quantizeLOS(x))
    dfcutQ["score_text"] = dfcutQ["score_text"].apply(lambda x: quantizeScore(x))
    dfcutQ["age_cat"] = dfcutQ["age_cat"].apply(lambda x: adjustAge(x))

    # Recode sex and race
    dfcutQ["sex"] = dfcutQ["sex"].replace({"Female": 1.0, "Male": 0.0})
    dfcutQ["race"] = dfcutQ["race"].apply(lambda x: group_race(x))

    features = [
        "two_year_recid",
        "sex",
        "race",
        "age_cat",
        "priors_count",
        "c_charge_degree",
    ]

    # Pass vallue to df
    df = dfcutQ[features]

    return df
def _perform_custom_preprocessing ( df ) : df = df [ [ "age" , "c_charge_degree" , "race" , "age_cat" , "score_text" , "sex" , "priors_count" , "days_b_screening_arrest" , "decile_score" , "is_recid" , "two_year_recid" , "c_jail_in" , "c_jail_out" , ] ] # Indices of data samples to keep ix = df [ "days_b_screening_arrest" ] <= 30 ix = ( df [ "days_b_screening_arrest" ] >= - 30 ) & ix ix = ( df [ "is_recid" ] != - 1 ) & ix ix = ( df [ "c_charge_degree" ] != "O" ) & ix ix = ( df [ "score_text" ] != "N/A" ) & ix df = df . loc [ ix , : ] df [ "length_of_stay" ] = ( pd . to_datetime ( df [ "c_jail_out" ] ) - pd . to_datetime ( df [ "c_jail_in" ] ) ) . apply ( lambda x : x . days ) # Restrict races to African-American and Caucasian dfcut = df . loc [ ~ df [ "race" ] . isin ( [ "Native American" , "Hispanic" , "Asian" , "Other" ] ) , : ] # Restrict the features to use dfcutQ = dfcut [ [ "sex" , "race" , "age_cat" , "c_charge_degree" , "score_text" , "priors_count" , "is_recid" , "two_year_recid" , "length_of_stay" , ] ] . copy ( ) # Quantize priors count between 0, 1-3, and >3 def quantizePrior ( x ) : if x <= 0 : return "0" elif 1 <= x <= 3 : return "1 to 3" else : return "More than 3" # Quantize length of stay def quantizeLOS ( x ) : if x <= 7 : return "<week" if 8 < x <= 93 : return "<3months" else : return ">3 months" # Quantize length of stay def adjustAge ( x ) : if x == "25 - 45" : return "25 to 45" else : return x # Quantize score_text to MediumHigh def quantizeScore ( x ) : if ( x == "High" ) | ( x == "Medium" ) : return "MediumHigh" else : return x def group_race ( x ) : if x == "Caucasian" : return 1.0 else : return 0.0 dfcutQ [ "priors_count" ] = dfcutQ [ "priors_count" ] . apply ( lambda x : quantizePrior ( x ) ) dfcutQ [ "length_of_stay" ] = dfcutQ [ "length_of_stay" ] . apply ( lambda x : quantizeLOS ( x ) ) dfcutQ [ "score_text" ] = dfcutQ [ "score_text" ] . apply ( lambda x : quantizeScore ( x ) ) dfcutQ [ "age_cat" ] = dfcutQ [ "age_cat" ] . apply ( lambda x : adjustAge ( x ) ) # Recode sex and race dfcutQ [ "sex" ] = dfcutQ [ "sex" ] . replace ( { "Female" : 1.0 , "Male" : 0.0 } ) dfcutQ [ "race" ] = dfcutQ [ "race" ] . apply ( lambda x : group_race ( x ) ) features = [ "two_year_recid" , "sex" , "race" , "age_cat" , "priors_count" , "c_charge_degree" , ] # Pass vallue to df df = dfcutQ [ features ] return df