mstz commited on
Commit
df2cb54
·
1 Parent(s): 9d1d08e

Upload 3 files

Browse files
Files changed (1) hide show
  1. australian_credit.py +91 -0
australian_credit.py CHANGED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Australian_credit"""
2
+
3
+ from typing import List
4
+
5
+ import datasets
6
+
7
+ import pandas
8
+
9
+
10
+ VERSION = datasets.Version("1.0.0")
11
+
12
+ DESCRIPTION = "Australian_credit dataset from the UCI ML repository."
13
+ _HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Australian_credit"
14
+ _URLS = ("https://archive.ics.uci.edu/ml/datasets/Australian_credit")
15
+ _CITATION = """
16
+ @misc{misc_statlog_(australian_credit_approval)_143,
17
+ author = {Quinlan,Ross},
18
+ title = {{Statlog (Australian Credit Approval)}},
19
+ howpublished = {UCI Machine Learning Repository},
20
+ note = {{DOI}: \\url{10.24432/C59012}}
21
+ }"""
22
+
23
+ # Dataset info
24
+ urls_per_split = {
25
+ "train": "https://huggingface.co/datasets/mstz/australian_credit/raw/main/australian.dat"
26
+ }
27
+ features_types_per_config = {
28
+ "australian_credit": {
29
+ "feature_1": datasets.Value("bool"),
30
+ "feature_2": datasets.Value("float64"),
31
+ "feature_3": datasets.Value("float64"),
32
+ "feature_4": datasets.Value("string"),
33
+ "feature_5": datasets.Value("string"),
34
+ "feature_6": datasets.Value("string"),
35
+ "feature_7": datasets.Value("float64"),
36
+ "feature_8": datasets.Value("string"),
37
+ "feature_9": datasets.Value("string"),
38
+ "feature_10": datasets.Value("float64"),
39
+ "feature_11": datasets.Value("string"),
40
+ "feature_12": datasets.Value("string"),
41
+ "feature_13": datasets.Value("float64"),
42
+ "feature_14": datasets.Value("float64"),
43
+ "is_granted": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
44
+ }
45
+
46
+ }
47
+ features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
48
+
49
+
50
+ class AustralianCreditConfig(datasets.BuilderConfig):
51
+ def __init__(self, **kwargs):
52
+ super(AustralianCreditConfig, self).__init__(version=VERSION, **kwargs)
53
+ self.features = features_per_config[kwargs["name"]]
54
+
55
+
56
+ class AustralianCredit(datasets.GeneratorBasedBuilder):
57
+ # dataset versions
58
+ DEFAULT_CONFIG = "australian_credit"
59
+ BUILDER_CONFIGS = [
60
+ AustralianCreditConfig(name="australian_credit",
61
+ description="Australian_credit for binary classification.")
62
+ ]
63
+
64
+
65
+ def _info(self):
66
+ info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
67
+ features=features_per_config[self.config.name])
68
+
69
+ return info
70
+
71
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
72
+ downloads = dl_manager.download_and_extract(urls_per_split)
73
+
74
+ return [
75
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]})
76
+ ]
77
+
78
+ def _generate_examples(self, filepath: str):
79
+ data = pandas.read_csv(filepath, header=None)
80
+ data = self.preprocess(data)
81
+
82
+ for row_id, row in data.iterrows():
83
+ data_row = dict(row)
84
+
85
+ yield row_id, data_row
86
+
87
+ def preprocess(self, data):
88
+ features = list(features_types_per_config[self.config.name])
89
+ data.features = features
90
+
91
+ return data