"""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