Datasets:
Upload german.py
Browse files
german.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
|
| 3 |
from typing import List
|
| 4 |
|
|
@@ -54,13 +54,83 @@ _BASE_FEATURE_NAMES = [
|
|
| 54 |
"is_foreign",
|
| 55 |
"loan_granted"
|
| 56 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
DESCRIPTION = "
|
| 59 |
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Statlog+%28German+Credit+Data%29"
|
| 60 |
_URLS = ("https://archive.ics.uci.edu/ml/datasets/Statlog+%28German+Credit+Data%29")
|
| 61 |
-
_CITATION = """
|
| 62 |
-
|
| 63 |
-
"""
|
| 64 |
|
| 65 |
# Dataset info
|
| 66 |
urls_per_split = {
|
|
@@ -101,19 +171,19 @@ features_types_per_config = {
|
|
| 101 |
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
| 102 |
|
| 103 |
|
| 104 |
-
class
|
| 105 |
def __init__(self, **kwargs):
|
| 106 |
-
super(
|
| 107 |
self.features = features_per_config[kwargs["name"]]
|
| 108 |
|
| 109 |
|
| 110 |
-
class
|
| 111 |
# dataset versions
|
| 112 |
DEFAULT_CONFIG = "loan"
|
| 113 |
BUILDER_CONFIGS = [
|
| 114 |
-
|
| 115 |
description="Encoding dictionaries for discrete features."),
|
| 116 |
-
|
| 117 |
description="Binary classification of loan approval."),
|
| 118 |
]
|
| 119 |
|
|
@@ -135,8 +205,12 @@ class Breast(datasets.GeneratorBasedBuilder):
|
|
| 135 |
]
|
| 136 |
|
| 137 |
def _generate_examples(self, filepath: str):
|
| 138 |
-
if self.config.name
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
else:
|
| 141 |
data = pandas.read_csv(filepath, sep=" ", header=None)
|
| 142 |
data.columns=_ORIGINAL_FEATURE_NAMES
|
|
@@ -147,54 +221,11 @@ class Breast(datasets.GeneratorBasedBuilder):
|
|
| 147 |
|
| 148 |
yield row_id, data_row
|
| 149 |
|
| 150 |
-
def
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
self.employed_since_encode_dic(),
|
| 156 |
-
self.guarantors_encode_dic(),
|
| 157 |
-
self.has_registered_phone_number_encode_dic(),
|
| 158 |
-
self.housing_status_encode_dic(),
|
| 159 |
-
self.installment_plans_encode_dic(),
|
| 160 |
-
self.is_foreign_encode_dic(),
|
| 161 |
-
self.job_status_encode_dic(),
|
| 162 |
-
self.marital_status_encode_dic(),
|
| 163 |
-
self.sex_encode_dic(),
|
| 164 |
-
])
|
| 165 |
-
data = [[(feature, value, code) for value, code in d.items()]
|
| 166 |
-
for feature, d in zip(["checking_account_status",
|
| 167 |
-
"credit_status",
|
| 168 |
-
"current_savings",
|
| 169 |
-
"employed_since",
|
| 170 |
-
"guarantors",
|
| 171 |
-
"has_registered_phone_number",
|
| 172 |
-
"housing_status",
|
| 173 |
-
"installment_plans",
|
| 174 |
-
"is_foreign",
|
| 175 |
-
"job_status",
|
| 176 |
-
"marital_status",
|
| 177 |
-
"sex"],
|
| 178 |
-
dictionaries)]
|
| 179 |
-
full_data = list()
|
| 180 |
-
for d in data:
|
| 181 |
-
full_data += d
|
| 182 |
-
data = pandas.DataFrame(full_data,
|
| 183 |
-
columns=["feature", "original_value", "encoded_value"])
|
| 184 |
-
|
| 185 |
-
return data
|
| 186 |
-
|
| 187 |
-
def preprocess(self, data: pandas.DataFrame, config: str = "cancer") -> pandas.DataFrame:
|
| 188 |
-
data.loc[:, "checking_account_status"] = data.checking_account_status.apply(self.encode_checking_account_status)
|
| 189 |
-
data.loc[:, "credit_status"] = data.credit_status.apply(self.encode_credit_status)
|
| 190 |
-
data.loc[:, "current_savings"] = data.current_savings.apply(self.encode_current_savings)
|
| 191 |
-
data.loc[:, "employed_since"] = data.employed_since.apply(self.encode_employed_since)
|
| 192 |
-
data.loc[:, "guarantors"] = data.guarantors.apply(self.encode_guarantors)
|
| 193 |
-
data.loc[:, "has_registered_phone_number"] = data.has_registered_phone_number.apply(self.encode_has_registered_phone_number)
|
| 194 |
-
data.loc[:, "housing_status"] = data.housing_status.apply(self.encode_housing_status)
|
| 195 |
-
data.loc[:, "installment_plans"] = data.installment_plans.apply(self.encode_installment_plans)
|
| 196 |
-
data.loc[:, "is_foreign"] = data.is_foreign.apply(self.encode_is_foreign)
|
| 197 |
-
data.loc[:, "job_status"] = data.job_status.apply(self.encode_job_status)
|
| 198 |
data.loc[:, "marital_status"] = data.personal_status_and_sex.apply(self.encode_marital_status)
|
| 199 |
data.loc[:, "sex"] = data.personal_status_and_sex.apply(self.encode_sex)
|
| 200 |
data.loc[:, "loan_purpose"] = data.loan_purpose.apply(self.encode_loan_purpose)
|
|
@@ -202,274 +233,11 @@ class Breast(datasets.GeneratorBasedBuilder):
|
|
| 202 |
|
| 203 |
data.drop("personal_status_and_sex", axis="columns", inplace=True)
|
| 204 |
|
| 205 |
-
print(data.sex.unique())
|
| 206 |
-
|
| 207 |
data = data[_BASE_FEATURE_NAMES]
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
raise ValueError(f"Unknown config: {config}")
|
| 213 |
-
|
| 214 |
-
def encode_checking_account_status(self, status):
|
| 215 |
-
return self.checking_account_status_encode_dic()[status]
|
| 216 |
-
|
| 217 |
-
def checking_account_status_encode_dic(self):
|
| 218 |
-
return {
|
| 219 |
-
"A14": 0,
|
| 220 |
-
"A11": 1,
|
| 221 |
-
"A12": 2,
|
| 222 |
-
"A13": 3,
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
def decode_checking_account_status(self, code):
|
| 226 |
-
return self.checking_account_status_decode_dic()[code]
|
| 227 |
-
|
| 228 |
-
def checking_account_status_decode_dic(self):
|
| 229 |
-
return {
|
| 230 |
-
0: "A14",
|
| 231 |
-
1: "A11",
|
| 232 |
-
2: "A12",
|
| 233 |
-
3: "A13",
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
def encode_credit_status(self, status):
|
| 237 |
-
return self.credit_status_encode_dic()[status]
|
| 238 |
-
|
| 239 |
-
def credit_status_encode_dic(self):
|
| 240 |
-
return {
|
| 241 |
-
"A30": 0,
|
| 242 |
-
"A31": 1,
|
| 243 |
-
"A32": 2,
|
| 244 |
-
"A33": 3,
|
| 245 |
-
"A34": 4,
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
-
def decode_credit_status(self, code):
|
| 249 |
-
return self.credit_status_decode_dic()[code]
|
| 250 |
-
|
| 251 |
-
def credit_status_decode_dic(self):
|
| 252 |
-
return {
|
| 253 |
-
0: "A30",
|
| 254 |
-
1: "A31",
|
| 255 |
-
2: "A32",
|
| 256 |
-
3: "A33",
|
| 257 |
-
4: "A34",
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
def encode_current_savings(self, status):
|
| 261 |
-
return self.current_savings_encode_dic()[status]
|
| 262 |
-
|
| 263 |
-
def current_savings_encode_dic(self):
|
| 264 |
-
return {
|
| 265 |
-
"A65": 0,
|
| 266 |
-
"A61": 1,
|
| 267 |
-
"A62": 2,
|
| 268 |
-
"A63": 3,
|
| 269 |
-
"A64": 4,
|
| 270 |
-
}
|
| 271 |
-
|
| 272 |
-
def decode_current_savings(self, code):
|
| 273 |
-
return self.current_savings_decode_dic()[code]
|
| 274 |
-
|
| 275 |
-
def current_savings_decode_dic(self):
|
| 276 |
-
return {
|
| 277 |
-
0: "A65",
|
| 278 |
-
1: "A61",
|
| 279 |
-
2: "A62",
|
| 280 |
-
3: "A63",
|
| 281 |
-
4: "A64",
|
| 282 |
-
}
|
| 283 |
-
|
| 284 |
-
def encode_employed_since(self, status):
|
| 285 |
-
return self.employed_since_encode_dic()[status]
|
| 286 |
-
|
| 287 |
-
def employed_since_encode_dic(self):
|
| 288 |
-
return {
|
| 289 |
-
"A71": 0,
|
| 290 |
-
"A72": 1,
|
| 291 |
-
"A73": 2,
|
| 292 |
-
"A74": 3,
|
| 293 |
-
"A75": 4,
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
def decode_employed_since(self, code):
|
| 297 |
-
return self.employed_since_decode_dic()[code]
|
| 298 |
-
|
| 299 |
-
def employed_since_decode_dic(self):
|
| 300 |
-
return {
|
| 301 |
-
0: "A71",
|
| 302 |
-
1: "A72",
|
| 303 |
-
2: "A73",
|
| 304 |
-
3: "A74",
|
| 305 |
-
4: "A75",
|
| 306 |
-
}
|
| 307 |
-
|
| 308 |
-
def encode_sex(self, status):
|
| 309 |
-
return self.sex_encode_dic()[status]
|
| 310 |
-
|
| 311 |
-
def sex_encode_dic(self):
|
| 312 |
-
return {
|
| 313 |
-
"A91": 0,
|
| 314 |
-
"A93": 0,
|
| 315 |
-
"A94": 0,
|
| 316 |
-
"A92": 1,
|
| 317 |
-
"A95": 1,
|
| 318 |
-
}
|
| 319 |
-
|
| 320 |
-
def decode_sex(self, code):
|
| 321 |
-
return self.sex_decode_dic()[code]
|
| 322 |
-
|
| 323 |
-
def sex_decode_dic(self):
|
| 324 |
-
return {
|
| 325 |
-
0: "A91",
|
| 326 |
-
1: "A92",
|
| 327 |
-
}
|
| 328 |
-
|
| 329 |
-
def encode_marital_status(self, status):
|
| 330 |
-
return self.marital_status_encode_dic()[status]
|
| 331 |
-
|
| 332 |
-
def marital_status_encode_dic(self):
|
| 333 |
-
return {
|
| 334 |
-
"A91": 0,
|
| 335 |
-
"A92": 0,
|
| 336 |
-
"A93": 1,
|
| 337 |
-
"A94": 2,
|
| 338 |
-
"A95": 1,
|
| 339 |
-
}
|
| 340 |
-
|
| 341 |
-
def decode_marital_status(self, code):
|
| 342 |
-
return self.marital_status_decode_dic()[code]
|
| 343 |
-
|
| 344 |
-
def marital_status_decode_dic(self):
|
| 345 |
-
return {
|
| 346 |
-
0: "A91",
|
| 347 |
-
1: "A93",
|
| 348 |
-
2: "A94",
|
| 349 |
-
}
|
| 350 |
-
|
| 351 |
-
def encode_guarantors(self, status):
|
| 352 |
-
return self.guarantors_encode_dic()[status]
|
| 353 |
-
|
| 354 |
-
def guarantors_encode_dic(self):
|
| 355 |
-
return {
|
| 356 |
-
"A101": 0,
|
| 357 |
-
"A102": 1,
|
| 358 |
-
"A103": 2,
|
| 359 |
-
}
|
| 360 |
-
|
| 361 |
-
def decode_guarantors(self, code):
|
| 362 |
-
return self.guarantors_decode_dic()[code]
|
| 363 |
-
|
| 364 |
-
def guarantors_decode_dic(self):
|
| 365 |
-
return {
|
| 366 |
-
0: "A101",
|
| 367 |
-
1: "A102",
|
| 368 |
-
2: "A103",
|
| 369 |
-
}
|
| 370 |
-
|
| 371 |
-
def encode_installment_plans(self, status):
|
| 372 |
-
return self.installment_plans_encode_dic()[status]
|
| 373 |
-
|
| 374 |
-
def installment_plans_encode_dic(self):
|
| 375 |
-
return {
|
| 376 |
-
"A141": 0,
|
| 377 |
-
"A142": 1,
|
| 378 |
-
"A143": 2,
|
| 379 |
-
}
|
| 380 |
-
|
| 381 |
-
def decode_installment_plans(self, code):
|
| 382 |
-
return self.installment_plans_decode_dic()[code]
|
| 383 |
-
|
| 384 |
-
def installment_plans_decode_dic(self):
|
| 385 |
-
return {
|
| 386 |
-
0: "A141",
|
| 387 |
-
1: "A142",
|
| 388 |
-
2: "A143",
|
| 389 |
-
}
|
| 390 |
-
|
| 391 |
-
def encode_housing_status(self, status):
|
| 392 |
-
return self.housing_status_encode_dic()[status]
|
| 393 |
-
|
| 394 |
-
def housing_status_encode_dic(self):
|
| 395 |
-
return {
|
| 396 |
-
"A153": 0,
|
| 397 |
-
"A151": 1,
|
| 398 |
-
"A152": 2,
|
| 399 |
-
}
|
| 400 |
-
|
| 401 |
-
def decode_housing_status(self, code):
|
| 402 |
-
return self.housing_status_decode_dic()[code]
|
| 403 |
-
|
| 404 |
-
def housing_status_decode_dic(self):
|
| 405 |
-
return {
|
| 406 |
-
0: "A153",
|
| 407 |
-
1: "A151",
|
| 408 |
-
2: "A152",
|
| 409 |
-
}
|
| 410 |
-
|
| 411 |
-
def encode_job_status(self, status):
|
| 412 |
-
return self.job_status_encode_dic()[status]
|
| 413 |
-
|
| 414 |
-
def job_status_encode_dic(self):
|
| 415 |
-
return {
|
| 416 |
-
"A171": 0,
|
| 417 |
-
"A172": 1,
|
| 418 |
-
"A173": 2,
|
| 419 |
-
"A174": 3,
|
| 420 |
-
}
|
| 421 |
-
|
| 422 |
-
def decode_job_status(self, code):
|
| 423 |
-
return self.job_status_decode_dic()[code]
|
| 424 |
-
|
| 425 |
-
def job_status_decode_dic(self):
|
| 426 |
-
return {
|
| 427 |
-
0: "A171",
|
| 428 |
-
1: "A172",
|
| 429 |
-
2: "A173",
|
| 430 |
-
3: "A174",
|
| 431 |
-
}
|
| 432 |
-
|
| 433 |
-
def encode_has_registered_phone_number(self, status):
|
| 434 |
-
return self.has_registered_phone_number_encode_dic()[status]
|
| 435 |
-
|
| 436 |
-
def has_registered_phone_number_encode_dic(self):
|
| 437 |
-
return {
|
| 438 |
-
"A191": 0,
|
| 439 |
-
"A192": 1,
|
| 440 |
-
}
|
| 441 |
-
|
| 442 |
-
def decode_has_registered_phone_number(self, code):
|
| 443 |
-
return self.has_registered_phone_number_decode_dic()[code]
|
| 444 |
-
|
| 445 |
-
def has_registered_phone_number_decode_dic(self):
|
| 446 |
-
return {
|
| 447 |
-
0: "A191",
|
| 448 |
-
1: "A192",
|
| 449 |
-
}
|
| 450 |
-
|
| 451 |
-
def encode_is_foreign(self, status):
|
| 452 |
-
return self.is_foreign_encode_dic()[status]
|
| 453 |
-
|
| 454 |
-
def is_foreign_encode_dic(self):
|
| 455 |
-
return {
|
| 456 |
-
"A201": 0,
|
| 457 |
-
"A202": 1,
|
| 458 |
-
}
|
| 459 |
-
|
| 460 |
-
def decode_is_foreign(self, code):
|
| 461 |
-
return self.is_foreign_decode_dic()[code]
|
| 462 |
-
|
| 463 |
-
def is_foreign_decode_dic(self):
|
| 464 |
-
return {
|
| 465 |
-
0: "A201",
|
| 466 |
-
1: "A202",
|
| 467 |
-
}
|
| 468 |
-
|
| 469 |
-
def encode_loan_purpose(self, status):
|
| 470 |
-
return self.loan_purpose_encode_dic()[status]
|
| 471 |
-
|
| 472 |
-
def loan_purpose_encode_dic(self):
|
| 473 |
return {
|
| 474 |
"A40": "new car",
|
| 475 |
"A41": "used car",
|
|
@@ -482,22 +250,4 @@ class Breast(datasets.GeneratorBasedBuilder):
|
|
| 482 |
"A48": "retraining",
|
| 483 |
"A49": "business",
|
| 484 |
"A410": "others"
|
| 485 |
-
}
|
| 486 |
-
|
| 487 |
-
def decode_loan_purpose(self, code):
|
| 488 |
-
return self.loan_purpose_decode_dic()[code]
|
| 489 |
-
|
| 490 |
-
def loan_purpose_decode_dic(self):
|
| 491 |
-
return {
|
| 492 |
-
"new car": "A40",
|
| 493 |
-
"used car": "A41",
|
| 494 |
-
"furniture/equipment": "A42",
|
| 495 |
-
"radio/television": "A43",
|
| 496 |
-
"domestic appliances": "A44",
|
| 497 |
-
"repairs": "A45",
|
| 498 |
-
"education": "A46",
|
| 499 |
-
"vacation ": "A47",
|
| 500 |
-
"retraining": "A48",
|
| 501 |
-
"business": "A49",
|
| 502 |
-
"others": "A410"
|
| 503 |
-
}
|
|
|
|
| 1 |
+
"""German Dataset"""
|
| 2 |
|
| 3 |
from typing import List
|
| 4 |
|
|
|
|
| 54 |
"is_foreign",
|
| 55 |
"loan_granted"
|
| 56 |
]
|
| 57 |
+
_ENCODING_DICS = {
|
| 58 |
+
"is_foreign": {
|
| 59 |
+
"A201": 0,
|
| 60 |
+
"A202": 1
|
| 61 |
+
},
|
| 62 |
+
"has_registered_phone_number": {
|
| 63 |
+
"A191": 0,
|
| 64 |
+
"A192": 1
|
| 65 |
+
},
|
| 66 |
+
"job_status": {
|
| 67 |
+
"A171": 0,
|
| 68 |
+
"A172": 1,
|
| 69 |
+
"A173": 2,
|
| 70 |
+
"A174": 3
|
| 71 |
+
},
|
| 72 |
+
"housing_status": {
|
| 73 |
+
"A153": 0,
|
| 74 |
+
"A151": 1,
|
| 75 |
+
"A152": 2
|
| 76 |
+
},
|
| 77 |
+
"installment_plans": {
|
| 78 |
+
"A141": 0,
|
| 79 |
+
"A142": 1,
|
| 80 |
+
"A143": 2
|
| 81 |
+
},
|
| 82 |
+
"guarantors": {
|
| 83 |
+
"A101": 0,
|
| 84 |
+
"A102": 1,
|
| 85 |
+
"A103": 2
|
| 86 |
+
},
|
| 87 |
+
"marital_status": {
|
| 88 |
+
"A91": 0,
|
| 89 |
+
"A92": 0,
|
| 90 |
+
"A93": 1,
|
| 91 |
+
"A94": 2,
|
| 92 |
+
"A95": 1,
|
| 93 |
+
},
|
| 94 |
+
"sex": {
|
| 95 |
+
"A91": 0,
|
| 96 |
+
"A93": 0,
|
| 97 |
+
"A94": 0,
|
| 98 |
+
"A92": 1,
|
| 99 |
+
"A95": 1,
|
| 100 |
+
},
|
| 101 |
+
"employed_since": {
|
| 102 |
+
"A71": 0,
|
| 103 |
+
"A72": 1,
|
| 104 |
+
"A73": 2,
|
| 105 |
+
"A74": 3,
|
| 106 |
+
"A75": 4,
|
| 107 |
+
},
|
| 108 |
+
"current_savings": {
|
| 109 |
+
"A65": 0,
|
| 110 |
+
"A61": 1,
|
| 111 |
+
"A62": 2,
|
| 112 |
+
"A63": 3,
|
| 113 |
+
"A64": 4,
|
| 114 |
+
},
|
| 115 |
+
"credit_status": {
|
| 116 |
+
"A30": 0,
|
| 117 |
+
"A31": 1,
|
| 118 |
+
"A32": 2,
|
| 119 |
+
"A33": 3,
|
| 120 |
+
"A34": 4,
|
| 121 |
+
},
|
| 122 |
+
"checking_account_status": {
|
| 123 |
+
"A14": 0,
|
| 124 |
+
"A11": 1,
|
| 125 |
+
"A12": 2,
|
| 126 |
+
"A13": 3,
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
|
| 130 |
+
DESCRIPTION = "German dataset for cancer prediction."
|
| 131 |
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Statlog+%28German+Credit+Data%29"
|
| 132 |
_URLS = ("https://archive.ics.uci.edu/ml/datasets/Statlog+%28German+Credit+Data%29")
|
| 133 |
+
_CITATION = """"""
|
|
|
|
|
|
|
| 134 |
|
| 135 |
# Dataset info
|
| 136 |
urls_per_split = {
|
|
|
|
| 171 |
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
| 172 |
|
| 173 |
|
| 174 |
+
class GermanConfig(datasets.BuilderConfig):
|
| 175 |
def __init__(self, **kwargs):
|
| 176 |
+
super(GermanConfig, self).__init__(version=VERSION, **kwargs)
|
| 177 |
self.features = features_per_config[kwargs["name"]]
|
| 178 |
|
| 179 |
|
| 180 |
+
class German(datasets.GeneratorBasedBuilder):
|
| 181 |
# dataset versions
|
| 182 |
DEFAULT_CONFIG = "loan"
|
| 183 |
BUILDER_CONFIGS = [
|
| 184 |
+
GermanConfig(name="encoding",
|
| 185 |
description="Encoding dictionaries for discrete features."),
|
| 186 |
+
GermanConfig(name="loan",
|
| 187 |
description="Binary classification of loan approval."),
|
| 188 |
]
|
| 189 |
|
|
|
|
| 205 |
]
|
| 206 |
|
| 207 |
def _generate_examples(self, filepath: str):
|
| 208 |
+
if self.config.name not in self.features_per_config:
|
| 209 |
+
raise ValueError(f"Unknown config: {self.config.name}")
|
| 210 |
+
|
| 211 |
+
elif self.config.name == "encoding":
|
| 212 |
+
data = self.encoding_dics()
|
| 213 |
+
|
| 214 |
else:
|
| 215 |
data = pandas.read_csv(filepath, sep=" ", header=None)
|
| 216 |
data.columns=_ORIGINAL_FEATURE_NAMES
|
|
|
|
| 221 |
|
| 222 |
yield row_id, data_row
|
| 223 |
|
| 224 |
+
def preprocess(self, data: pandas.DataFrame, config: str = "loan") -> pandas.DataFrame:
|
| 225 |
+
for feature in _ENCODING_DICS:
|
| 226 |
+
if feature not in ["marital_status", "sex"]:
|
| 227 |
+
encoding_function = partial(self.encode, feature)
|
| 228 |
+
data.loc[:, feature] = data[feature].apply(encoding_function)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
data.loc[:, "marital_status"] = data.personal_status_and_sex.apply(self.encode_marital_status)
|
| 230 |
data.loc[:, "sex"] = data.personal_status_and_sex.apply(self.encode_sex)
|
| 231 |
data.loc[:, "loan_purpose"] = data.loan_purpose.apply(self.encode_loan_purpose)
|
|
|
|
| 233 |
|
| 234 |
data.drop("personal_status_and_sex", axis="columns", inplace=True)
|
| 235 |
|
|
|
|
|
|
|
| 236 |
data = data[_BASE_FEATURE_NAMES]
|
| 237 |
|
| 238 |
+
return data
|
| 239 |
+
|
| 240 |
+
def encode_loan_purpose(self, code):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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