|
"""VertebralColumn""" |
|
|
|
from typing import List |
|
|
|
import datasets |
|
|
|
import pandas |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
DESCRIPTION = "VertebralColumn dataset from the UCI ML repository." |
|
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/VertebralColumn" |
|
_URLS = ("https://archive.ics.uci.edu/ml/datasets/VertebralColumn") |
|
_CITATION = """ |
|
@misc{misc_vertebral_column_212, |
|
author = {Barreto,Guilherme & Neto,Ajalmar}, |
|
title = {{Vertebral Column}}, |
|
year = {2011}, |
|
howpublished = {UCI Machine Learning Repository}, |
|
note = {{DOI}: \\url{10.24432/C5K89B}} |
|
}""" |
|
|
|
|
|
urls_per_split = { |
|
"train": "https://huggingface.co/datasets/mstz/vertebral_column/raw/main/data.csv" |
|
} |
|
features_types_per_config = { |
|
"abnormal": { |
|
"pelvic_incidence": datasets.Value("float64"), |
|
"pelvic_tilt": datasets.Value("float64"), |
|
"lumbar_lordosis_angle": datasets.Value("float64"), |
|
"sacral_slope": datasets.Value("float64"), |
|
"pelvic_radius": datasets.Value("float64"), |
|
"degree_spondylolisthesis": datasets.Value("float64"), |
|
"is_abnormal": 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 VertebralColumnConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
super(VertebralColumnConfig, self).__init__(version=VERSION, **kwargs) |
|
self.features = features_per_config[kwargs["name"]] |
|
|
|
|
|
class VertebralColumn(datasets.GeneratorBasedBuilder): |
|
|
|
DEFAULT_CONFIG = "abnormal" |
|
BUILDER_CONFIGS = [ |
|
VertebralColumnConfig(name="abnormal", |
|
description="VertebralColumn 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) |
|
|
|
for row_id, row in data.iterrows(): |
|
data_row = dict(row) |
|
|
|
yield row_id, data_row |
|
|