|
"""Ozone: A Census Dataset""" |
|
|
|
from typing import List |
|
|
|
import datasets |
|
|
|
import pandas |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
_BASE_FEATURE_NAMES = [ |
|
"Date", |
|
"WSR0", |
|
"WSR1", |
|
"WSR2", |
|
"WSR3", |
|
"WSR4", |
|
"WSR5", |
|
"WSR6", |
|
"WSR7", |
|
"WSR8", |
|
"WSR9", |
|
"WSR10", |
|
"WSR11", |
|
"WSR12", |
|
"WSR13", |
|
"WSR14", |
|
"WSR15", |
|
"WSR16", |
|
"WSR17", |
|
"WSR18", |
|
"WSR19", |
|
"WSR20", |
|
"WSR21", |
|
"WSR22", |
|
"WSR23", |
|
"WSR_PK", |
|
"WSR_AV", |
|
"T0", |
|
"T1", |
|
"T2", |
|
"T3", |
|
"T4", |
|
"T5", |
|
"T6", |
|
"T7", |
|
"T8", |
|
"T9", |
|
"T10", |
|
"T11", |
|
"T12", |
|
"T13", |
|
"T14", |
|
"T15", |
|
"T16", |
|
"T17", |
|
"T18", |
|
"T19", |
|
"T20", |
|
"T21", |
|
"T22", |
|
"T23", |
|
"T_PK", |
|
"T_AV", |
|
"T85", |
|
"RH85", |
|
"U85", |
|
"V85", |
|
"HT85", |
|
"T70", |
|
"RH70", |
|
"U70", |
|
"V70", |
|
"HT70", |
|
"T50", |
|
"RH50", |
|
"U50", |
|
"V50", |
|
"HT50", |
|
"KI", |
|
"TT", |
|
"SLP", |
|
"SLP_", |
|
"Precp", |
|
"Class" |
|
] |
|
|
|
DESCRIPTION = "Ozone dataset from the UCI ML repository." |
|
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Ozone" |
|
_URLS = ("https://archive.ics.uci.edu/ml/datasets/Ozone") |
|
_CITATION = """ |
|
@misc{misc_ozone_level_detection_172, |
|
author = {Zhang,Kun, Fan,Wei & Yuan,XiaoJing}, |
|
title = {{Ozone Level Detection}}, |
|
year = {2008}, |
|
howpublished = {UCI Machine Learning Repository}, |
|
note = {{DOI}: \\url{10.24432/C5NG6W}} |
|
}""" |
|
|
|
|
|
urls_per_split = { |
|
"8hr": {"train": "https://huggingface.co/datasets/mstz/ozone/raw/main/eighthr.data"}, |
|
"1hr": {"train": "https://huggingface.co/datasets/mstz/ozone/raw/main/onehr.data"}, |
|
} |
|
features_types_per_config = { |
|
"8hr": { |
|
"WSR0": datasets.Value("float64"), |
|
"WSR1": datasets.Value("float64"), |
|
"WSR2": datasets.Value("float64"), |
|
"WSR3": datasets.Value("float64"), |
|
"WSR4": datasets.Value("float64"), |
|
"WSR5": datasets.Value("float64"), |
|
"WSR6": datasets.Value("float64"), |
|
"WSR7": datasets.Value("float64"), |
|
"WSR8": datasets.Value("float64"), |
|
"WSR9": datasets.Value("float64"), |
|
"WSR10": datasets.Value("float64"), |
|
"WSR11": datasets.Value("float64"), |
|
"WSR12": datasets.Value("float64"), |
|
"WSR13": datasets.Value("float64"), |
|
"WSR14": datasets.Value("float64"), |
|
"WSR15": datasets.Value("float64"), |
|
"WSR16": datasets.Value("float64"), |
|
"WSR17": datasets.Value("float64"), |
|
"WSR18": datasets.Value("float64"), |
|
"WSR19": datasets.Value("float64"), |
|
"WSR20": datasets.Value("float64"), |
|
"WSR21": datasets.Value("float64"), |
|
"WSR22": datasets.Value("float64"), |
|
"WSR23": datasets.Value("float64"), |
|
"WSR_PK": datasets.Value("float64"), |
|
"WSR_AV": datasets.Value("float64"), |
|
"T0": datasets.Value("float64"), |
|
"T1": datasets.Value("float64"), |
|
"T2": datasets.Value("float64"), |
|
"T3": datasets.Value("float64"), |
|
"T4": datasets.Value("float64"), |
|
"T5": datasets.Value("float64"), |
|
"T6": datasets.Value("float64"), |
|
"T7": datasets.Value("float64"), |
|
"T8": datasets.Value("float64"), |
|
"T9": datasets.Value("float64"), |
|
"T10": datasets.Value("float64"), |
|
"T11": datasets.Value("float64"), |
|
"T12": datasets.Value("float64"), |
|
"T13": datasets.Value("float64"), |
|
"T14": datasets.Value("float64"), |
|
"T15": datasets.Value("float64"), |
|
"T16": datasets.Value("float64"), |
|
"T17": datasets.Value("float64"), |
|
"T18": datasets.Value("float64"), |
|
"T19": datasets.Value("float64"), |
|
"T20": datasets.Value("float64"), |
|
"T21": datasets.Value("float64"), |
|
"T22": datasets.Value("float64"), |
|
"T23": datasets.Value("float64"), |
|
"T_PK": datasets.Value("float64"), |
|
"T_AV": datasets.Value("float64"), |
|
"T85": datasets.Value("float64"), |
|
"RH85": datasets.Value("float64"), |
|
"U85": datasets.Value("float64"), |
|
"V85": datasets.Value("float64"), |
|
"HT85": datasets.Value("float64"), |
|
"T70": datasets.Value("float64"), |
|
"RH70": datasets.Value("float64"), |
|
"U70": datasets.Value("float64"), |
|
"V70": datasets.Value("float64"), |
|
"HT70": datasets.Value("float64"), |
|
"T50": datasets.Value("float64"), |
|
"RH50": datasets.Value("float64"), |
|
"U50": datasets.Value("float64"), |
|
"V50": datasets.Value("float64"), |
|
"HT50": datasets.Value("float64"), |
|
"KI": datasets.Value("float64"), |
|
"TT": datasets.Value("float64"), |
|
"SLP": datasets.Value("float64"), |
|
"SLP_": datasets.Value("float64"), |
|
"Precp": datasets.Value("float64"), |
|
"Class": datasets.ClassLabel(num_classes=2, names=("no", "yes")) |
|
}, |
|
"1hr": { |
|
"WSR0": datasets.Value("float64"), |
|
"WSR1": datasets.Value("float64"), |
|
"WSR2": datasets.Value("float64"), |
|
"WSR3": datasets.Value("float64"), |
|
"WSR4": datasets.Value("float64"), |
|
"WSR5": datasets.Value("float64"), |
|
"WSR6": datasets.Value("float64"), |
|
"WSR7": datasets.Value("float64"), |
|
"WSR8": datasets.Value("float64"), |
|
"WSR9": datasets.Value("float64"), |
|
"WSR10": datasets.Value("float64"), |
|
"WSR11": datasets.Value("float64"), |
|
"WSR12": datasets.Value("float64"), |
|
"WSR13": datasets.Value("float64"), |
|
"WSR14": datasets.Value("float64"), |
|
"WSR15": datasets.Value("float64"), |
|
"WSR16": datasets.Value("float64"), |
|
"WSR17": datasets.Value("float64"), |
|
"WSR18": datasets.Value("float64"), |
|
"WSR19": datasets.Value("float64"), |
|
"WSR20": datasets.Value("float64"), |
|
"WSR21": datasets.Value("float64"), |
|
"WSR22": datasets.Value("float64"), |
|
"WSR23": datasets.Value("float64"), |
|
"WSR_PK": datasets.Value("float64"), |
|
"WSR_AV": datasets.Value("float64"), |
|
"T0": datasets.Value("float64"), |
|
"T1": datasets.Value("float64"), |
|
"T2": datasets.Value("float64"), |
|
"T3": datasets.Value("float64"), |
|
"T4": datasets.Value("float64"), |
|
"T5": datasets.Value("float64"), |
|
"T6": datasets.Value("float64"), |
|
"T7": datasets.Value("float64"), |
|
"T8": datasets.Value("float64"), |
|
"T9": datasets.Value("float64"), |
|
"T10": datasets.Value("float64"), |
|
"T11": datasets.Value("float64"), |
|
"T12": datasets.Value("float64"), |
|
"T13": datasets.Value("float64"), |
|
"T14": datasets.Value("float64"), |
|
"T15": datasets.Value("float64"), |
|
"T16": datasets.Value("float64"), |
|
"T17": datasets.Value("float64"), |
|
"T18": datasets.Value("float64"), |
|
"T19": datasets.Value("float64"), |
|
"T20": datasets.Value("float64"), |
|
"T21": datasets.Value("float64"), |
|
"T22": datasets.Value("float64"), |
|
"T23": datasets.Value("float64"), |
|
"T_PK": datasets.Value("float64"), |
|
"T_AV": datasets.Value("float64"), |
|
"T85": datasets.Value("float64"), |
|
"RH85": datasets.Value("float64"), |
|
"U85": datasets.Value("float64"), |
|
"V85": datasets.Value("float64"), |
|
"HT85": datasets.Value("float64"), |
|
"T70": datasets.Value("float64"), |
|
"RH70": datasets.Value("float64"), |
|
"U70": datasets.Value("float64"), |
|
"V70": datasets.Value("float64"), |
|
"HT70": datasets.Value("float64"), |
|
"T50": datasets.Value("float64"), |
|
"RH50": datasets.Value("float64"), |
|
"U50": datasets.Value("float64"), |
|
"V50": datasets.Value("float64"), |
|
"HT50": datasets.Value("float64"), |
|
"KI": datasets.Value("float64"), |
|
"TT": datasets.Value("float64"), |
|
"SLP": datasets.Value("float64"), |
|
"SLP_": datasets.Value("float64"), |
|
"Precp": datasets.Value("float64"), |
|
"Class": 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 OzoneConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
super(OzoneConfig, self).__init__(version=VERSION, **kwargs) |
|
self.features = features_per_config[kwargs["name"]] |
|
|
|
|
|
class Ozone(datasets.GeneratorBasedBuilder): |
|
|
|
DEFAULT_CONFIG = "8hr" |
|
BUILDER_CONFIGS = [ |
|
OzoneConfig(name="8hr", |
|
description="Ozone for binary classification."), |
|
OzoneConfig(name="1hr", |
|
description="Ozone 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) |
|
data.drop("Date", axis="columns", inplace=True) |
|
data.loc[:, "Class"] = data.Class.astype(int) |
|
data = data[~(data.isin(["?"]).any(axis=1))] |
|
data = data.infer_objects() |
|
|
|
for row_id, row in data.iterrows(): |
|
data_row = dict(row) |
|
|
|
yield row_id, data_row |
|
|