Datasets:
File size: 9,689 Bytes
0f70e69 00802e9 0f70e69 85d4271 0f70e69 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
"""Musk: A Census Dataset"""
from typing import List
from functools import partial
import datasets
import pandas
VERSION = datasets.Version("1.0.0")
_BASE_FEATURE_NAMES = [
"name",
"conformation_name",
"ray_0",
"ray_1",
"ray_2",
"ray_3",
"ray_4",
"ray_5",
"ray_6",
"ray_7",
"ray_8",
"ray_9",
"ray_10",
"ray_11",
"ray_12",
"ray_13",
"ray_14",
"ray_15",
"ray_16",
"ray_17",
"ray_18",
"ray_19",
"ray_20",
"ray_21",
"ray_22",
"ray_23",
"ray_24",
"ray_25",
"ray_26",
"ray_27",
"ray_28",
"ray_29",
"ray_30",
"ray_31",
"ray_32",
"ray_33",
"ray_34",
"ray_35",
"ray_36",
"ray_37",
"ray_38",
"ray_39",
"ray_40",
"ray_41",
"ray_42",
"ray_43",
"ray_44",
"ray_45",
"ray_46",
"ray_47",
"ray_48",
"ray_49",
"ray_50",
"ray_51",
"ray_52",
"ray_53",
"ray_54",
"ray_55",
"ray_56",
"ray_57",
"ray_58",
"ray_59",
"ray_60",
"ray_61",
"oxy_distance",
"displacement_1",
"displacement_2",
"displacement_3",
"is_musk"
]
DESCRIPTION = "Musk dataset from the UCI ML repository."
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Musk"
_URLS = ("https://huggingface.co/datasets/mstz/musk/raw/musk.csv")
_CITATION = """
@misc{misc_musk_(version_1)_74,
author = {Chapman,David & Jain,Ajay},
title = {{Musk (Version 1)}},
year = {1994},
howpublished = {UCI Machine Learning Repository},
note = {{DOI}: \\url{10.24432/C5ZK5B}}
}"""
# Dataset info
urls_per_split = {
"musk1": {
"train": "https://huggingface.co/datasets/mstz/musk/raw/main/clean1.data"
},
"musk2": {
"train": "https://huggingface.co/datasets/mstz/musk/raw/main/clean2.data"
}
}
features_types_per_config = {
"musk1": {
"ray_0": datasets.Value("float64"),
"ray_1": datasets.Value("float64"),
"ray_2": datasets.Value("float64"),
"ray_3": datasets.Value("float64"),
"ray_4": datasets.Value("float64"),
"ray_5": datasets.Value("float64"),
"ray_6": datasets.Value("float64"),
"ray_7": datasets.Value("float64"),
"ray_8": datasets.Value("float64"),
"ray_9": datasets.Value("float64"),
"ray_10": datasets.Value("float64"),
"ray_11": datasets.Value("float64"),
"ray_12": datasets.Value("float64"),
"ray_13": datasets.Value("float64"),
"ray_14": datasets.Value("float64"),
"ray_15": datasets.Value("float64"),
"ray_16": datasets.Value("float64"),
"ray_17": datasets.Value("float64"),
"ray_18": datasets.Value("float64"),
"ray_19": datasets.Value("float64"),
"ray_20": datasets.Value("float64"),
"ray_21": datasets.Value("float64"),
"ray_22": datasets.Value("float64"),
"ray_23": datasets.Value("float64"),
"ray_24": datasets.Value("float64"),
"ray_25": datasets.Value("float64"),
"ray_26": datasets.Value("float64"),
"ray_27": datasets.Value("float64"),
"ray_28": datasets.Value("float64"),
"ray_29": datasets.Value("float64"),
"ray_30": datasets.Value("float64"),
"ray_31": datasets.Value("float64"),
"ray_32": datasets.Value("float64"),
"ray_33": datasets.Value("float64"),
"ray_34": datasets.Value("float64"),
"ray_35": datasets.Value("float64"),
"ray_36": datasets.Value("float64"),
"ray_37": datasets.Value("float64"),
"ray_38": datasets.Value("float64"),
"ray_39": datasets.Value("float64"),
"ray_40": datasets.Value("float64"),
"ray_41": datasets.Value("float64"),
"ray_42": datasets.Value("float64"),
"ray_43": datasets.Value("float64"),
"ray_44": datasets.Value("float64"),
"ray_45": datasets.Value("float64"),
"ray_46": datasets.Value("float64"),
"ray_47": datasets.Value("float64"),
"ray_48": datasets.Value("float64"),
"ray_49": datasets.Value("float64"),
"ray_50": datasets.Value("float64"),
"ray_51": datasets.Value("float64"),
"ray_52": datasets.Value("float64"),
"ray_53": datasets.Value("float64"),
"ray_54": datasets.Value("float64"),
"ray_55": datasets.Value("float64"),
"ray_56": datasets.Value("float64"),
"ray_57": datasets.Value("float64"),
"ray_58": datasets.Value("float64"),
"ray_59": datasets.Value("float64"),
"ray_60": datasets.Value("float64"),
"ray_61": datasets.Value("float64"),
"oxy_distance": datasets.Value("float64"),
"displacement_1": datasets.Value("float64"),
"displacement_2": datasets.Value("float64"),
"displacement_3": datasets.Value("float64"),
"is_musk": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
},
"musk2": {
"ray_0": datasets.Value("float64"),
"ray_1": datasets.Value("float64"),
"ray_2": datasets.Value("float64"),
"ray_3": datasets.Value("float64"),
"ray_4": datasets.Value("float64"),
"ray_5": datasets.Value("float64"),
"ray_6": datasets.Value("float64"),
"ray_7": datasets.Value("float64"),
"ray_8": datasets.Value("float64"),
"ray_9": datasets.Value("float64"),
"ray_10": datasets.Value("float64"),
"ray_11": datasets.Value("float64"),
"ray_12": datasets.Value("float64"),
"ray_13": datasets.Value("float64"),
"ray_14": datasets.Value("float64"),
"ray_15": datasets.Value("float64"),
"ray_16": datasets.Value("float64"),
"ray_17": datasets.Value("float64"),
"ray_18": datasets.Value("float64"),
"ray_19": datasets.Value("float64"),
"ray_20": datasets.Value("float64"),
"ray_21": datasets.Value("float64"),
"ray_22": datasets.Value("float64"),
"ray_23": datasets.Value("float64"),
"ray_24": datasets.Value("float64"),
"ray_25": datasets.Value("float64"),
"ray_26": datasets.Value("float64"),
"ray_27": datasets.Value("float64"),
"ray_28": datasets.Value("float64"),
"ray_29": datasets.Value("float64"),
"ray_30": datasets.Value("float64"),
"ray_31": datasets.Value("float64"),
"ray_32": datasets.Value("float64"),
"ray_33": datasets.Value("float64"),
"ray_34": datasets.Value("float64"),
"ray_35": datasets.Value("float64"),
"ray_36": datasets.Value("float64"),
"ray_37": datasets.Value("float64"),
"ray_38": datasets.Value("float64"),
"ray_39": datasets.Value("float64"),
"ray_40": datasets.Value("float64"),
"ray_41": datasets.Value("float64"),
"ray_42": datasets.Value("float64"),
"ray_43": datasets.Value("float64"),
"ray_44": datasets.Value("float64"),
"ray_45": datasets.Value("float64"),
"ray_46": datasets.Value("float64"),
"ray_47": datasets.Value("float64"),
"ray_48": datasets.Value("float64"),
"ray_49": datasets.Value("float64"),
"ray_50": datasets.Value("float64"),
"ray_51": datasets.Value("float64"),
"ray_52": datasets.Value("float64"),
"ray_53": datasets.Value("float64"),
"ray_54": datasets.Value("float64"),
"ray_55": datasets.Value("float64"),
"ray_56": datasets.Value("float64"),
"ray_57": datasets.Value("float64"),
"ray_58": datasets.Value("float64"),
"ray_59": datasets.Value("float64"),
"ray_60": datasets.Value("float64"),
"ray_61": datasets.Value("float64"),
"oxy_distance": datasets.Value("float64"),
"displacement_1": datasets.Value("float64"),
"displacement_2": datasets.Value("float64"),
"displacement_3": datasets.Value("float64"),
"is_musk": 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 MuskConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(MuskConfig, self).__init__(version=VERSION, **kwargs)
self.features = features_per_config[kwargs["name"]]
class Musk(datasets.GeneratorBasedBuilder):
# dataset versions
DEFAULT_CONFIG = "musk1"
BUILDER_CONFIGS = [
MuskConfig(name="musk1",
description="Musk for binary classification."),
MuskConfig(name="musk2",
description="Musk 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[self.config.name]["train"]})
]
def _generate_examples(self, filepath: str):
data = pandas.read_csv(filepath, header=None)
data.columns = _BASE_FEATURE_NAMES
data = data.drop("name", axis="columns", inplace=True)
data = data.drop("conformation_name", axis="columns", inplace=True)
for row_id, row in data.iterrows():
data_row = dict(row)
yield row_id, data_row
|