"""Musk: A Census Dataset""" from typing import List 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", "ray_62", "ray_63", "ray_64", "ray_65", "ray_66", "ray_67", "ray_68", "ray_69", "ray_70", "ray_71", "ray_72", "ray_73", "ray_74", "ray_75", "ray_76", "ray_77", "ray_78", "ray_79", "ray_80", "ray_81", "ray_82", "ray_83", "ray_84", "ray_85", "ray_86", "ray_87", "ray_88", "ray_89", "ray_90", "ray_91", "ray_92", "ray_93", "ray_94", "ray_95", "ray_96", "ray_97", "ray_98", "ray_99", "ray_100", "ray_101", "ray_102", "ray_103", "ray_104", "ray_105", "ray_106", "ray_107", "ray_108", "ray_109", "ray_110", "ray_111", "ray_112", "ray_113", "ray_114", "ray_115", "ray_116", "ray_117", "ray_118", "ray_119", "ray_120", "ray_121", "ray_122", "ray_123", "ray_124", "ray_125", "ray_126", "ray_127", "ray_128", "ray_129", "ray_130", "ray_131", "ray_132", "ray_133", "ray_134", "ray_135", "ray_136", "ray_137", "ray_138", "ray_139", "ray_140", "ray_141", "ray_142", "ray_143", "ray_144", "ray_145", "ray_146", "ray_147", "ray_148", "ray_149", "ray_150", "ray_151", "ray_152", "ray_153", "ray_154", "ray_155", "ray_156", "ray_157", "ray_158", "ray_159", "ray_160", "ray_161", "oxy_distance", "displacement_1", "displacement_2", "displacement_3", "is_muskV2" ] DESCRIPTION = "Musk dataset from the UCI ML repository." _HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Musk" _URLS = ("https://archive.ics.uci.edu/ml/datasets/Musk") _CITATION = """ @misc{misc_musk_(version_2)_75, author = {Chapman,David & Jain,Ajay}, title = {{Musk (Version 2)}}, year = {1994}, howpublished = {UCI Machine Learning Repository}, note = {{DOI}: \\url{10.24432/C51608}} }""" # Dataset info urls_per_split = { "train": "https://huggingface.co./datasets/mstz/muskV2/raw/main/clean1.data" } features_types_per_config = { "musk": { "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"), "ray_62": datasets.Value("float64"), "ray_63": datasets.Value("float64"), "ray_64": datasets.Value("float64"), "ray_65": datasets.Value("float64"), "ray_66": datasets.Value("float64"), "ray_67": datasets.Value("float64"), "ray_68": datasets.Value("float64"), "ray_69": datasets.Value("float64"), "ray_70": datasets.Value("float64"), "ray_71": datasets.Value("float64"), "ray_72": datasets.Value("float64"), "ray_73": datasets.Value("float64"), "ray_74": datasets.Value("float64"), "ray_75": datasets.Value("float64"), "ray_76": datasets.Value("float64"), "ray_77": datasets.Value("float64"), "ray_78": datasets.Value("float64"), "ray_79": datasets.Value("float64"), "ray_80": datasets.Value("float64"), "ray_81": datasets.Value("float64"), "ray_82": datasets.Value("float64"), "ray_83": datasets.Value("float64"), "ray_84": datasets.Value("float64"), "ray_85": datasets.Value("float64"), "ray_86": datasets.Value("float64"), "ray_87": datasets.Value("float64"), "ray_88": datasets.Value("float64"), "ray_89": datasets.Value("float64"), "ray_90": datasets.Value("float64"), "ray_91": datasets.Value("float64"), "ray_92": datasets.Value("float64"), "ray_93": datasets.Value("float64"), "ray_94": datasets.Value("float64"), "ray_95": datasets.Value("float64"), "ray_96": datasets.Value("float64"), "ray_97": datasets.Value("float64"), "ray_98": datasets.Value("float64"), "ray_99": datasets.Value("float64"), "ray_100": datasets.Value("float64"), "ray_101": datasets.Value("float64"), "ray_102": datasets.Value("float64"), "ray_103": datasets.Value("float64"), "ray_104": datasets.Value("float64"), "ray_105": datasets.Value("float64"), "ray_106": datasets.Value("float64"), "ray_107": datasets.Value("float64"), "ray_108": datasets.Value("float64"), "ray_109": datasets.Value("float64"), "ray_110": datasets.Value("float64"), "ray_111": datasets.Value("float64"), "ray_112": datasets.Value("float64"), "ray_113": datasets.Value("float64"), "ray_114": datasets.Value("float64"), "ray_115": datasets.Value("float64"), "ray_116": datasets.Value("float64"), "ray_117": datasets.Value("float64"), "ray_118": datasets.Value("float64"), "ray_119": datasets.Value("float64"), "ray_120": datasets.Value("float64"), "ray_121": datasets.Value("float64"), "ray_122": datasets.Value("float64"), "ray_123": datasets.Value("float64"), "ray_124": datasets.Value("float64"), "ray_125": datasets.Value("float64"), "ray_126": datasets.Value("float64"), "ray_127": datasets.Value("float64"), "ray_128": datasets.Value("float64"), "ray_129": datasets.Value("float64"), "ray_130": datasets.Value("float64"), "ray_131": datasets.Value("float64"), "ray_132": datasets.Value("float64"), "ray_133": datasets.Value("float64"), "ray_134": datasets.Value("float64"), "ray_135": datasets.Value("float64"), "ray_136": datasets.Value("float64"), "ray_137": datasets.Value("float64"), "ray_138": datasets.Value("float64"), "ray_139": datasets.Value("float64"), "ray_140": datasets.Value("float64"), "ray_141": datasets.Value("float64"), "ray_142": datasets.Value("float64"), "ray_143": datasets.Value("float64"), "ray_144": datasets.Value("float64"), "ray_145": datasets.Value("float64"), "ray_146": datasets.Value("float64"), "ray_147": datasets.Value("float64"), "ray_148": datasets.Value("float64"), "ray_149": datasets.Value("float64"), "ray_150": datasets.Value("float64"), "ray_151": datasets.Value("float64"), "ray_152": datasets.Value("float64"), "ray_153": datasets.Value("float64"), "ray_154": datasets.Value("float64"), "ray_155": datasets.Value("float64"), "ray_156": datasets.Value("float64"), "ray_157": datasets.Value("float64"), "ray_158": datasets.Value("float64"), "ray_159": datasets.Value("float64"), "ray_160": datasets.Value("float64"), "ray_161": 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 = "musk" BUILDER_CONFIGS = [ MuskConfig(name="musk", 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["train"]}) ] def _generate_examples(self, filepath: str): data = pandas.read_csv(filepath, header=None) data.columns = _BASE_FEATURE_NAMES data.drop("name", axis="columns", inplace=True) data.drop("conformation_name", axis="columns", inplace=True) for row_id, row in data.iterrows(): data_row = dict(row) yield row_id, data_row