|
"""Australian_credit""" |
|
|
|
from typing import List |
|
|
|
import datasets |
|
|
|
import pandas |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
DESCRIPTION = "Australian_credit dataset from the UCI ML repository." |
|
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Australian_credit" |
|
_URLS = ("https://archive.ics.uci.edu/ml/datasets/Australian_credit") |
|
_CITATION = """ |
|
@misc{misc_statlog_(australian_credit_approval)_143, |
|
author = {Quinlan,Ross}, |
|
title = {{Statlog (Australian Credit Approval)}}, |
|
howpublished = {UCI Machine Learning Repository}, |
|
note = {{DOI}: \\url{10.24432/C59012}} |
|
}""" |
|
|
|
|
|
urls_per_split = { |
|
"train": "https://huggingface.co/datasets/mstz/australian_credit/raw/main/australian.dat" |
|
} |
|
features_types_per_config = { |
|
"australian_credit": { |
|
"feature_1": datasets.Value("bool"), |
|
"feature_2": datasets.Value("float64"), |
|
"feature_3": datasets.Value("float64"), |
|
"feature_4": datasets.Value("string"), |
|
"feature_5": datasets.Value("string"), |
|
"feature_6": datasets.Value("string"), |
|
"feature_7": datasets.Value("float64"), |
|
"feature_8": datasets.Value("string"), |
|
"feature_9": datasets.Value("string"), |
|
"feature_10": datasets.Value("float64"), |
|
"feature_11": datasets.Value("string"), |
|
"feature_12": datasets.Value("string"), |
|
"feature_13": datasets.Value("float64"), |
|
"feature_14": datasets.Value("float64"), |
|
"is_granted": datasets.ClassLabel(num_classes=2, names=("no", "yes")) |
|
} |
|
|
|
} |
|
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config} |
|
|
|
|
|
class AustralianCreditConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
super(AustralianCreditConfig, self).__init__(version=VERSION, **kwargs) |
|
self.features = features_per_config[kwargs["name"]] |
|
|
|
|
|
class AustralianCredit(datasets.GeneratorBasedBuilder): |
|
|
|
DEFAULT_CONFIG = "australian_credit" |
|
BUILDER_CONFIGS = [ |
|
AustralianCreditConfig(name="australian_credit", |
|
description="Australian_credit for binary classification.") |
|
] |
|
|
|
|
|
def _info(self): |
|
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE, |
|
features=features_per_config[self.config.name]) |
|
|
|
return info |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: |
|
downloads = dl_manager.download_and_extract(urls_per_split) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}) |
|
] |
|
|
|
def _generate_examples(self, filepath: str): |
|
data = pandas.read_csv(filepath, header=None, sep=" ") |
|
data = self.preprocess(data) |
|
|
|
for row_id, row in data.iterrows(): |
|
data_row = dict(row) |
|
|
|
yield row_id, data_row |
|
|
|
def preprocess(self, data): |
|
features = list(features_types_per_config[self.config.name]) |
|
data.columns = features |
|
|
|
return data |
|
|