Datasets:
Upload hayes_roth.py
Browse files- hayes_roth.py +31 -31
hayes_roth.py
CHANGED
@@ -24,43 +24,43 @@ _CITATION = """
|
|
24 |
# Dataset info
|
25 |
_BASE_FEATURE_NAMES = [
|
26 |
"name",
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
]
|
33 |
urls_per_split = {
|
34 |
"train": "https://huggingface.co/datasets/mstz/hayes/raw/main/hayes_roth.data"
|
35 |
}
|
36 |
features_types_per_config = {
|
37 |
"hayes": {
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
},
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
},
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
},
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
}
|
65 |
}
|
66 |
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
@@ -107,13 +107,13 @@ class Hayes(datasets.GeneratorBasedBuilder):
|
|
107 |
|
108 |
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
109 |
data.columns = _BASE_FEATURE_NAMES
|
110 |
-
|
111 |
|
112 |
if self.config.name == "hayes_1":
|
113 |
data.loc[:, "class"] = data["class"].apply(lambda x: 1 if x == 1 else 0)
|
114 |
-
|
115 |
data.loc[:, "class"] = data["class"].apply(lambda x: 1 if x == 2 else 0)
|
116 |
-
|
117 |
data.loc[:, "class"] = data["class"].apply(lambda x: 1 if x == 3 else 0)
|
118 |
|
119 |
return data
|
|
|
24 |
# Dataset info
|
25 |
_BASE_FEATURE_NAMES = [
|
26 |
"name",
|
27 |
+
"hobby",
|
28 |
+
"age",
|
29 |
+
"educational_level",
|
30 |
+
"marital_level",
|
31 |
+
"class"
|
32 |
]
|
33 |
urls_per_split = {
|
34 |
"train": "https://huggingface.co/datasets/mstz/hayes/raw/main/hayes_roth.data"
|
35 |
}
|
36 |
features_types_per_config = {
|
37 |
"hayes": {
|
38 |
+
"hobby": datasets.Value("string"),
|
39 |
+
"age": datasets.Value("int8"),
|
40 |
+
"educational_level": datasets.Value("int8"),
|
41 |
+
"marital_level": datasets.Value("string"),
|
42 |
+
"class": datasets.ClassLabel(num_classes=3)
|
43 |
},
|
44 |
+
"hayes_1": {
|
45 |
+
"hobby": datasets.Value("string"),
|
46 |
+
"age": datasets.Value("int8"),
|
47 |
+
"educational_level": datasets.Value("int8"),
|
48 |
+
"marital_level": datasets.Value("string"),
|
49 |
+
"class": datasets.ClassLabel(num_classes=2)
|
50 |
},
|
51 |
+
"hayes_2": {
|
52 |
+
"hobby": datasets.Value("string"),
|
53 |
+
"age": datasets.Value("int8"),
|
54 |
+
"educational_level": datasets.Value("int8"),
|
55 |
+
"marital_level": datasets.Value("string"),
|
56 |
+
"class": datasets.ClassLabel(num_classes=2)
|
57 |
},
|
58 |
+
"hayes_3": {
|
59 |
+
"hobby": datasets.Value("string"),
|
60 |
+
"age": datasets.Value("int8"),
|
61 |
+
"educational_level": datasets.Value("int8"),
|
62 |
+
"marital_level": datasets.Value("string"),
|
63 |
+
"class": datasets.ClassLabel(num_classes=2)
|
64 |
}
|
65 |
}
|
66 |
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
|
|
107 |
|
108 |
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
109 |
data.columns = _BASE_FEATURE_NAMES
|
110 |
+
data.drop("name", axis="columns", inplace=True)
|
111 |
|
112 |
if self.config.name == "hayes_1":
|
113 |
data.loc[:, "class"] = data["class"].apply(lambda x: 1 if x == 1 else 0)
|
114 |
+
elif self.config.name == "hayes_2":
|
115 |
data.loc[:, "class"] = data["class"].apply(lambda x: 1 if x == 2 else 0)
|
116 |
+
elif self.config.name == "hayes_3":
|
117 |
data.loc[:, "class"] = data["class"].apply(lambda x: 1 if x == 3 else 0)
|
118 |
|
119 |
return data
|