Datasets:
Upload compas.py
Browse files
compas.py
CHANGED
|
@@ -76,7 +76,6 @@ _BASE_FEATURE_NAMES = [
|
|
| 76 |
"number_of_prior_offenses",
|
| 77 |
"days_before_screening_arrest",
|
| 78 |
"is_recidivous",
|
| 79 |
-
"days_of_recidividity_after_arrest",
|
| 80 |
"days_in_custody",
|
| 81 |
"is_violent_recidivous",
|
| 82 |
"violence_decile_score",
|
|
@@ -110,7 +109,6 @@ features_types_per_config = {
|
|
| 110 |
"number_of_prior_offenses": datasets.Value("int64"),
|
| 111 |
"days_before_screening_arrest": datasets.Value("int64"),
|
| 112 |
"is_recidivous": datasets.Value("int64"),
|
| 113 |
-
"days_of_recidividity_after_arrest": datasets.Value("int64"),
|
| 114 |
"days_in_custody": datasets.Value("int64"),
|
| 115 |
"is_violent_recidivous": datasets.Value("int64"),
|
| 116 |
"violence_decile_score": datasets.Value("int64"),
|
|
@@ -127,7 +125,6 @@ features_types_per_config = {
|
|
| 127 |
"number_of_prior_offenses": datasets.Value("int64"),
|
| 128 |
"days_before_screening_arrest": datasets.Value("int64"),
|
| 129 |
"is_recidivous": datasets.Value("int64"),
|
| 130 |
-
"days_of_recidividity_after_arrest": datasets.Value("int64"),
|
| 131 |
"days_in_custody": datasets.Value("int64"),
|
| 132 |
"is_violent_recidivous": datasets.Value("int64"),
|
| 133 |
"violence_decile_score": datasets.Value("int64"),
|
|
@@ -144,7 +141,6 @@ features_types_per_config = {
|
|
| 144 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
| 145 |
"days_before_screening_arrest": datasets.Value("int64"),
|
| 146 |
"is_recidivous": datasets.Value("int64"),
|
| 147 |
-
"days_of_recidividity_after_arrest": datasets.Value("int64"),
|
| 148 |
"days_in_custody": datasets.Value("int64"),
|
| 149 |
"is_violent_recidivous": datasets.Value("int64"),
|
| 150 |
"violence_decile_score": datasets.Value("int64"),
|
|
@@ -161,7 +157,6 @@ features_types_per_config = {
|
|
| 161 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
| 162 |
"days_before_screening_arrest": datasets.Value("int64"),
|
| 163 |
"is_recidivous": datasets.Value("int64"),
|
| 164 |
-
"days_of_recidividity_after_arrest": datasets.Value("int64"),
|
| 165 |
"days_in_custody": datasets.Value("int64"),
|
| 166 |
"is_violent_recidivous": datasets.Value("int64"),
|
| 167 |
"violence_decile_score": datasets.Value("int64"),
|
|
@@ -259,13 +254,12 @@ class Compas(datasets.GeneratorBasedBuilder):
|
|
| 259 |
data.drop("priors_count.1", axis="columns", inplace=True)
|
| 260 |
data.drop("c_case_number", axis="columns", inplace=True)
|
| 261 |
data.drop("c_days_from_compas", axis="columns", inplace=True)
|
|
|
|
|
|
|
| 262 |
|
| 263 |
# handle nan values
|
| 264 |
data.loc[data.days_b_screening_arrest.isna(), "days_b_screening_arrest"] = -1
|
| 265 |
data.loc[:, "days_b_screening_arrest"] = data.days_b_screening_arrest.astype(int)
|
| 266 |
-
print("dropping from " + str(data.shape[0]))
|
| 267 |
-
data = data[~data.r_days_from_arrest.isna()]
|
| 268 |
-
print("dropped to" + str(data.shape[0]))
|
| 269 |
|
| 270 |
# transform columns into intervals
|
| 271 |
print("dropping from " + str(data.shape[0]))
|
|
@@ -324,7 +318,6 @@ class Compas(datasets.GeneratorBasedBuilder):
|
|
| 324 |
def two_years_recidividity_preprocessing(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
| 325 |
# categorize features
|
| 326 |
data.loc[:, "race"] = data.race.apply(self.encode_race)
|
| 327 |
-
data.loc[:, "days_of_recidividity_after_arrest"] = data.days_of_recidividity_after_arrest.astype(int)
|
| 328 |
|
| 329 |
return data
|
| 330 |
|
|
|
|
| 76 |
"number_of_prior_offenses",
|
| 77 |
"days_before_screening_arrest",
|
| 78 |
"is_recidivous",
|
|
|
|
| 79 |
"days_in_custody",
|
| 80 |
"is_violent_recidivous",
|
| 81 |
"violence_decile_score",
|
|
|
|
| 109 |
"number_of_prior_offenses": datasets.Value("int64"),
|
| 110 |
"days_before_screening_arrest": datasets.Value("int64"),
|
| 111 |
"is_recidivous": datasets.Value("int64"),
|
|
|
|
| 112 |
"days_in_custody": datasets.Value("int64"),
|
| 113 |
"is_violent_recidivous": datasets.Value("int64"),
|
| 114 |
"violence_decile_score": datasets.Value("int64"),
|
|
|
|
| 125 |
"number_of_prior_offenses": datasets.Value("int64"),
|
| 126 |
"days_before_screening_arrest": datasets.Value("int64"),
|
| 127 |
"is_recidivous": datasets.Value("int64"),
|
|
|
|
| 128 |
"days_in_custody": datasets.Value("int64"),
|
| 129 |
"is_violent_recidivous": datasets.Value("int64"),
|
| 130 |
"violence_decile_score": datasets.Value("int64"),
|
|
|
|
| 141 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
| 142 |
"days_before_screening_arrest": datasets.Value("int64"),
|
| 143 |
"is_recidivous": datasets.Value("int64"),
|
|
|
|
| 144 |
"days_in_custody": datasets.Value("int64"),
|
| 145 |
"is_violent_recidivous": datasets.Value("int64"),
|
| 146 |
"violence_decile_score": datasets.Value("int64"),
|
|
|
|
| 157 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
| 158 |
"days_before_screening_arrest": datasets.Value("int64"),
|
| 159 |
"is_recidivous": datasets.Value("int64"),
|
|
|
|
| 160 |
"days_in_custody": datasets.Value("int64"),
|
| 161 |
"is_violent_recidivous": datasets.Value("int64"),
|
| 162 |
"violence_decile_score": datasets.Value("int64"),
|
|
|
|
| 254 |
data.drop("priors_count.1", axis="columns", inplace=True)
|
| 255 |
data.drop("c_case_number", axis="columns", inplace=True)
|
| 256 |
data.drop("c_days_from_compas", axis="columns", inplace=True)
|
| 257 |
+
data.drop("r_days_from_arrest", axis="columns", inplace=True)
|
| 258 |
+
|
| 259 |
|
| 260 |
# handle nan values
|
| 261 |
data.loc[data.days_b_screening_arrest.isna(), "days_b_screening_arrest"] = -1
|
| 262 |
data.loc[:, "days_b_screening_arrest"] = data.days_b_screening_arrest.astype(int)
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
# transform columns into intervals
|
| 265 |
print("dropping from " + str(data.shape[0]))
|
|
|
|
| 318 |
def two_years_recidividity_preprocessing(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
| 319 |
# categorize features
|
| 320 |
data.loc[:, "race"] = data.race.apply(self.encode_race)
|
|
|
|
| 321 |
|
| 322 |
return data
|
| 323 |
|