Datasets:
Upload 3 files
Browse files- README.md +22 -1
- nursery.data +0 -0
- nursery.py +111 -0
README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
tags:
|
| 5 |
+
- nursery
|
| 6 |
+
- tabular_classification
|
| 7 |
+
pretty_name: Nursery
|
| 8 |
+
size_categories:
|
| 9 |
+
- 1K<n<10K
|
| 10 |
+
task_categories: # Full list at https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
|
| 11 |
+
- tabular-classification
|
| 12 |
+
configs:
|
| 13 |
+
- nursery
|
| 14 |
+
- nursery_binary
|
| 15 |
---
|
| 16 |
+
# Nursery
|
| 17 |
+
The [Nursery dataset](https://archive-beta.ics.uci.edu/dataset/76/nursery) from the [UCI repository](https://archive-beta.ics.uci.edu/).
|
| 18 |
+
Should the nursery school accept the student application?
|
| 19 |
+
|
| 20 |
+
# Configurations and tasks
|
| 21 |
+
| **Configuration** | **Task** |
|
| 22 |
+
|-------------------|---------------------------|
|
| 23 |
+
| nursery | Multiclass classification |
|
| 24 |
+
| nursery_binary | Binary classification |
|
nursery.data
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
nursery.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Nursery Dataset"""
|
| 2 |
+
|
| 3 |
+
from typing import List
|
| 4 |
+
from functools import partial
|
| 5 |
+
|
| 6 |
+
import datasets
|
| 7 |
+
|
| 8 |
+
import pandas
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
VERSION = datasets.Version("1.0.0")
|
| 12 |
+
|
| 13 |
+
_ENCODING_DICS = {}
|
| 14 |
+
|
| 15 |
+
DESCRIPTION = "Nursery dataset."
|
| 16 |
+
_HOMEPAGE = "https://archive-beta.ics.uci.edu/dataset/69/molecular+biology+nursery+junction+gene+sequences"
|
| 17 |
+
_URLS = ("https://archive-beta.ics.uci.edu/dataset/69/molecular+biology+nursery+junction+gene+sequences")
|
| 18 |
+
_CITATION = """
|
| 19 |
+
@misc{misc_nursery_76,
|
| 20 |
+
author = {Rajkovic,Vladislav},
|
| 21 |
+
title = {{Nursery}},
|
| 22 |
+
year = {1997},
|
| 23 |
+
howpublished = {UCI Machine Learning Repository},
|
| 24 |
+
note = {{DOI}: \\url{10.24432/C5P88W}}
|
| 25 |
+
}
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
# Dataset info
|
| 29 |
+
urls_per_split = {
|
| 30 |
+
"train": "https://huggingface.co/datasets/mstz/nursery/raw/main/nursery.data"
|
| 31 |
+
}
|
| 32 |
+
features_types_per_config = {
|
| 33 |
+
"nursery": {
|
| 34 |
+
"parents_attitude": datasets.Value("string"),
|
| 35 |
+
"current_nursery_status": datasets.Value("string"),
|
| 36 |
+
"form": datasets.Value("string"),
|
| 37 |
+
"number_of_children": datasets.Value("string"),
|
| 38 |
+
"housing_status": datasets.Value("string"),
|
| 39 |
+
"is_family_financially_stable": datasets.Value("bool"),
|
| 40 |
+
"social_status": datasets.Value("string"),
|
| 41 |
+
"health_status": datasets.Value("string"),
|
| 42 |
+
"recommendation": datasets.ClassLabel(num_classes=3, names=("not recommended", "recommended", "priority recommendation"))
|
| 43 |
+
},
|
| 44 |
+
"nursery_binary": {
|
| 45 |
+
"parents_attitude": datasets.Value("string"),
|
| 46 |
+
"current_nursery_status": datasets.Value("string"),
|
| 47 |
+
"form": datasets.Value("string"),
|
| 48 |
+
"number_of_children": datasets.Value("string"),
|
| 49 |
+
"housing_status": datasets.Value("string"),
|
| 50 |
+
"is_family_financially_stable": datasets.Value("bool"),
|
| 51 |
+
"social_status": datasets.Value("string"),
|
| 52 |
+
"health_status": datasets.Value("string"),
|
| 53 |
+
"recommendation": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
|
| 54 |
+
},
|
| 55 |
+
}
|
| 56 |
+
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class NurseryConfig(datasets.BuilderConfig):
|
| 60 |
+
def __init__(self, **kwargs):
|
| 61 |
+
super(NurseryConfig, self).__init__(version=VERSION, **kwargs)
|
| 62 |
+
self.features = features_per_config[kwargs["name"]]
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class Nursery(datasets.GeneratorBasedBuilder):
|
| 66 |
+
# dataset versions
|
| 67 |
+
DEFAULT_CONFIG = "nursery"
|
| 68 |
+
BUILDER_CONFIGS = [
|
| 69 |
+
NurseryConfig(name="nursery",
|
| 70 |
+
description="Nursery for multiclass classification."),
|
| 71 |
+
NurseryConfig(name="nursery_binary",
|
| 72 |
+
description="Nursery for binary classification.")
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _info(self):
|
| 77 |
+
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
|
| 78 |
+
features=features_per_config[self.config.name])
|
| 79 |
+
|
| 80 |
+
return info
|
| 81 |
+
|
| 82 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 83 |
+
downloads = dl_manager.download_and_extract(urls_per_split)
|
| 84 |
+
|
| 85 |
+
return [
|
| 86 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}),
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
def _generate_examples(self, filepath: str):
|
| 90 |
+
data = pandas.read_csv(filepath)
|
| 91 |
+
data = self.preprocess(data)
|
| 92 |
+
|
| 93 |
+
for row_id, row in data.iterrows():
|
| 94 |
+
data_row = dict(row)
|
| 95 |
+
|
| 96 |
+
yield row_id, data_row
|
| 97 |
+
|
| 98 |
+
def preprocess(self, data: pandas.DataFrame) -> pandas.DataFrame:
|
| 99 |
+
if self.config.name == "nursery_binary":
|
| 100 |
+
data["recommendation"] = data["recommendation"].apply(lambda x: 1 if x > 0 else 0)
|
| 101 |
+
|
| 102 |
+
for feature in _ENCODING_DICS:
|
| 103 |
+
encoding_function = partial(self.encode, feature)
|
| 104 |
+
data.loc[:, feature] = data[feature].apply(encoding_function)
|
| 105 |
+
|
| 106 |
+
return data[list(features_types_per_config[self.config.name].keys())]
|
| 107 |
+
|
| 108 |
+
def encode(self, feature, value):
|
| 109 |
+
if feature in _ENCODING_DICS:
|
| 110 |
+
return _ENCODING_DICS[feature][value]
|
| 111 |
+
raise ValueError(f"Unknown feature: {feature}")
|