Datasets:
Update compas.py
Browse files
compas.py
CHANGED
@@ -84,8 +84,8 @@ _BASE_FEATURE_NAMES = [
|
|
84 |
]
|
85 |
_ENCODING_DICS = {
|
86 |
"sex": {
|
87 |
-
"Male":
|
88 |
-
"Female":
|
89 |
},
|
90 |
"race": {
|
91 |
"Caucasian": 0,
|
@@ -114,7 +114,7 @@ features_types_per_config = {
|
|
114 |
},
|
115 |
|
116 |
"two-years-recidividity": {
|
117 |
-
"
|
118 |
"age": datasets.Value("int64"),
|
119 |
"race": datasets.Value("string"),
|
120 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
@@ -123,15 +123,15 @@ features_types_per_config = {
|
|
123 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
124 |
"number_of_prior_offenses": datasets.Value("int64"),
|
125 |
"days_before_screening_arrest": datasets.Value("int64"),
|
126 |
-
"is_recidivous": datasets.Value("
|
127 |
"days_in_custody": datasets.Value("int64"),
|
128 |
-
"is_violent_recidivous": datasets.Value("
|
129 |
"violence_decile_score": datasets.Value("int64"),
|
130 |
"two_year_recidivous": datasets.ClassLabel(num_classes=2, names=("no", "yes")),
|
131 |
},
|
132 |
|
133 |
"two-years-recidividity-no-race": {
|
134 |
-
"
|
135 |
"age": datasets.Value("int64"),
|
136 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
137 |
"decile_score": datasets.Value("int64"),
|
@@ -139,15 +139,15 @@ features_types_per_config = {
|
|
139 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
140 |
"number_of_prior_offenses": datasets.Value("int64"),
|
141 |
"days_before_screening_arrest": datasets.Value("int64"),
|
142 |
-
"is_recidivous": datasets.Value("
|
143 |
"days_in_custody": datasets.Value("int64"),
|
144 |
-
"is_violent_recidivous": datasets.Value("
|
145 |
"violence_decile_score": datasets.Value("int64"),
|
146 |
"two_year_recidivous": datasets.ClassLabel(num_classes=2, names=("no", "yes")),
|
147 |
},
|
148 |
|
149 |
"priors-prediction": {
|
150 |
-
"
|
151 |
"age": datasets.Value("int64"),
|
152 |
"race": datasets.Value("string"),
|
153 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
@@ -155,41 +155,41 @@ features_types_per_config = {
|
|
155 |
"number_of_juvenile_misdemeanors": datasets.Value("int64"),
|
156 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
157 |
"days_before_screening_arrest": datasets.Value("int64"),
|
158 |
-
"is_recidivous": datasets.Value("
|
159 |
"days_in_custody": datasets.Value("int64"),
|
160 |
-
"is_violent_recidivous": datasets.Value("
|
161 |
"violence_decile_score": datasets.Value("int64"),
|
162 |
"two_year_recidivous": datasets.Value("int64"),
|
163 |
"number_of_prior_offenses": datasets.Value("int64")
|
164 |
},
|
165 |
|
166 |
"priors-prediction-no-race": {
|
167 |
-
"
|
168 |
"age": datasets.Value("int64"),
|
169 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
170 |
"decile_score": datasets.Value("int64"),
|
171 |
"number_of_juvenile_misdemeanors": datasets.Value("int64"),
|
172 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
173 |
"days_before_screening_arrest": datasets.Value("int64"),
|
174 |
-
"is_recidivous": datasets.Value("
|
175 |
"days_in_custody": datasets.Value("int64"),
|
176 |
-
"is_violent_recidivous": datasets.Value("
|
177 |
"violence_decile_score": datasets.Value("int64"),
|
178 |
"two_year_recidivous": datasets.Value("int64"),
|
179 |
"number_of_prior_offenses": datasets.Value("int64"),
|
180 |
},
|
181 |
|
182 |
"race": {
|
183 |
-
"
|
184 |
"age": datasets.Value("int64"),
|
185 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
186 |
"decile_score": datasets.Value("int64"),
|
187 |
"number_of_juvenile_misdemeanors": datasets.Value("int64"),
|
188 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
189 |
"days_before_screening_arrest": datasets.Value("int64"),
|
190 |
-
"is_recidivous": datasets.Value("
|
191 |
"days_in_custody": datasets.Value("int64"),
|
192 |
-
"is_violent_recidivous": datasets.Value("
|
193 |
"violence_decile_score": datasets.Value("int64"),
|
194 |
"two_year_recidivous": datasets.Value("int64"),
|
195 |
"number_of_prior_offenses": datasets.Value("int64"),
|
@@ -210,8 +210,6 @@ class Compas(datasets.GeneratorBasedBuilder):
|
|
210 |
# dataset versions
|
211 |
DEFAULT_CONFIG = "two-years-recidividity"
|
212 |
BUILDER_CONFIGS = [
|
213 |
-
CompasConfig(name="encoding",
|
214 |
-
description="Encoding dictionaries for discrete labels."),
|
215 |
CompasConfig(name="race",
|
216 |
description="Multiclass classification, predict `race` out of other features."),
|
217 |
CompasConfig(name="two-years-recidividity",
|
@@ -222,13 +220,12 @@ class Compas(datasets.GeneratorBasedBuilder):
|
|
222 |
description="Compas regression task for estimating number of prior offenses of defendant."),
|
223 |
CompasConfig(name="priors-prediction-no-race",
|
224 |
description="Compas regression task for estimating number of prior offenses of defendant. Race excluded from features."),
|
|
|
|
|
225 |
]
|
226 |
|
227 |
|
228 |
-
def _info(self):
|
229 |
-
if self.config.name not in features_per_config:
|
230 |
-
raise ValueError(f"Unknown configuration: {self.config.name}")
|
231 |
-
|
232 |
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
233 |
features=features_per_config[self.config.name])
|
234 |
|
@@ -242,9 +239,6 @@ class Compas(datasets.GeneratorBasedBuilder):
|
|
242 |
]
|
243 |
|
244 |
def _generate_examples(self, filepath: str):
|
245 |
-
if self.config.name not in features_types_per_config:
|
246 |
-
raise ValueError(f"Unknown config: {self.config.name}")
|
247 |
-
|
248 |
if self.config.name == "encoding":
|
249 |
data = self.encoding_dics()
|
250 |
else:
|
@@ -334,6 +328,9 @@ class Compas(datasets.GeneratorBasedBuilder):
|
|
334 |
continue
|
335 |
encoding_function = partial(self.encode, feature)
|
336 |
data.loc[:, feature] = data[feature].apply(encoding_function)
|
|
|
|
|
|
|
337 |
|
338 |
return data[list(features_types_per_config[config].keys())]
|
339 |
|
|
|
84 |
]
|
85 |
_ENCODING_DICS = {
|
86 |
"sex": {
|
87 |
+
"Male": 1,
|
88 |
+
"Female": 0
|
89 |
},
|
90 |
"race": {
|
91 |
"Caucasian": 0,
|
|
|
114 |
},
|
115 |
|
116 |
"two-years-recidividity": {
|
117 |
+
"is_male": datasets.Value("bool"),
|
118 |
"age": datasets.Value("int64"),
|
119 |
"race": datasets.Value("string"),
|
120 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
|
|
123 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
124 |
"number_of_prior_offenses": datasets.Value("int64"),
|
125 |
"days_before_screening_arrest": datasets.Value("int64"),
|
126 |
+
"is_recidivous": datasets.Value("bool"),
|
127 |
"days_in_custody": datasets.Value("int64"),
|
128 |
+
"is_violent_recidivous": datasets.Value("bool"),
|
129 |
"violence_decile_score": datasets.Value("int64"),
|
130 |
"two_year_recidivous": datasets.ClassLabel(num_classes=2, names=("no", "yes")),
|
131 |
},
|
132 |
|
133 |
"two-years-recidividity-no-race": {
|
134 |
+
"is_male": datasets.Value("bool"),
|
135 |
"age": datasets.Value("int64"),
|
136 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
137 |
"decile_score": datasets.Value("int64"),
|
|
|
139 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
140 |
"number_of_prior_offenses": datasets.Value("int64"),
|
141 |
"days_before_screening_arrest": datasets.Value("int64"),
|
142 |
+
"is_recidivous": datasets.Value("bool"),
|
143 |
"days_in_custody": datasets.Value("int64"),
|
144 |
+
"is_violent_recidivous": datasets.Value("bool"),
|
145 |
"violence_decile_score": datasets.Value("int64"),
|
146 |
"two_year_recidivous": datasets.ClassLabel(num_classes=2, names=("no", "yes")),
|
147 |
},
|
148 |
|
149 |
"priors-prediction": {
|
150 |
+
"is_male": datasets.Value("bool"),
|
151 |
"age": datasets.Value("int64"),
|
152 |
"race": datasets.Value("string"),
|
153 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
|
|
155 |
"number_of_juvenile_misdemeanors": datasets.Value("int64"),
|
156 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
157 |
"days_before_screening_arrest": datasets.Value("int64"),
|
158 |
+
"is_recidivous": datasets.Value("bool"),
|
159 |
"days_in_custody": datasets.Value("int64"),
|
160 |
+
"is_violent_recidivous": datasets.Value("bool"),
|
161 |
"violence_decile_score": datasets.Value("int64"),
|
162 |
"two_year_recidivous": datasets.Value("int64"),
|
163 |
"number_of_prior_offenses": datasets.Value("int64")
|
164 |
},
|
165 |
|
166 |
"priors-prediction-no-race": {
|
167 |
+
"is_male": datasets.Value("bool"),
|
168 |
"age": datasets.Value("int64"),
|
169 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
170 |
"decile_score": datasets.Value("int64"),
|
171 |
"number_of_juvenile_misdemeanors": datasets.Value("int64"),
|
172 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
173 |
"days_before_screening_arrest": datasets.Value("int64"),
|
174 |
+
"is_recidivous": datasets.Value("bool"),
|
175 |
"days_in_custody": datasets.Value("int64"),
|
176 |
+
"is_violent_recidivous": datasets.Value("bool"),
|
177 |
"violence_decile_score": datasets.Value("int64"),
|
178 |
"two_year_recidivous": datasets.Value("int64"),
|
179 |
"number_of_prior_offenses": datasets.Value("int64"),
|
180 |
},
|
181 |
|
182 |
"race": {
|
183 |
+
"is_male": datasets.Value("bool"),
|
184 |
"age": datasets.Value("int64"),
|
185 |
"number_of_juvenile_fellonies": datasets.Value("int64"),
|
186 |
"decile_score": datasets.Value("int64"),
|
187 |
"number_of_juvenile_misdemeanors": datasets.Value("int64"),
|
188 |
"number_of_other_juvenile_offenses": datasets.Value("int64"),
|
189 |
"days_before_screening_arrest": datasets.Value("int64"),
|
190 |
+
"is_recidivous": datasets.Value("bool"),
|
191 |
"days_in_custody": datasets.Value("int64"),
|
192 |
+
"is_violent_recidivous": datasets.Value("bool"),
|
193 |
"violence_decile_score": datasets.Value("int64"),
|
194 |
"two_year_recidivous": datasets.Value("int64"),
|
195 |
"number_of_prior_offenses": datasets.Value("int64"),
|
|
|
210 |
# dataset versions
|
211 |
DEFAULT_CONFIG = "two-years-recidividity"
|
212 |
BUILDER_CONFIGS = [
|
|
|
|
|
213 |
CompasConfig(name="race",
|
214 |
description="Multiclass classification, predict `race` out of other features."),
|
215 |
CompasConfig(name="two-years-recidividity",
|
|
|
220 |
description="Compas regression task for estimating number of prior offenses of defendant."),
|
221 |
CompasConfig(name="priors-prediction-no-race",
|
222 |
description="Compas regression task for estimating number of prior offenses of defendant. Race excluded from features."),
|
223 |
+
CompasConfig(name="encoding",
|
224 |
+
description="Encoding dictionaries for discrete labels."),
|
225 |
]
|
226 |
|
227 |
|
228 |
+
def _info(self):
|
|
|
|
|
|
|
229 |
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
230 |
features=features_per_config[self.config.name])
|
231 |
|
|
|
239 |
]
|
240 |
|
241 |
def _generate_examples(self, filepath: str):
|
|
|
|
|
|
|
242 |
if self.config.name == "encoding":
|
243 |
data = self.encoding_dics()
|
244 |
else:
|
|
|
328 |
continue
|
329 |
encoding_function = partial(self.encode, feature)
|
330 |
data.loc[:, feature] = data[feature].apply(encoding_function)
|
331 |
+
data.loc[:, "is_recidivous"] = data["is_recidivous"].apply(bool)
|
332 |
+
data.loc[:, "is_violent_recidivous"] = data["is_violent_recidivous"].apply(bool)
|
333 |
+
data = data.astype({"is_recidivous": "bool", "is_violent_recidivous": "bool"})
|
334 |
|
335 |
return data[list(features_types_per_config[config].keys())]
|
336 |
|