spambase / spambase.py
mstz's picture
Upload 2 files
d4b3c39
"""Spambase: A Census Dataset"""
from typing import List
import datasets
import pandas
VERSION = datasets.Version("1.0.0")
DESCRIPTION = "Spambase dataset from the UCI ML repository."
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Spambase"
_URLS = ("https://archive.ics.uci.edu/ml/datasets/Spambase")
_CITATION = """
@misc{misc_spambase_94,
author = {Hopkins,Mark, Reeber,Erik, Forman,George & Suermondt,Jaap},
title = {{Spambase}},
year = {1999},
howpublished = {UCI Machine Learning Repository},
note = {{DOI}: \\url{10.24432/C53G6X}}
}"""
# Dataset info
urls_per_split = {
"train": "https://huggingface.co/datasets/mstz/spambase/raw/main/spambase.data"
}
features_types_per_config = {
"spambase": {
"word_freq_make": datasets.Value("float64"),
"word_freq_address": datasets.Value("float64"),
"word_freq_all": datasets.Value("float64"),
"word_freq_3d": datasets.Value("float64"),
"word_freq_our": datasets.Value("float64"),
"word_freq_over": datasets.Value("float64"),
"word_freq_remove": datasets.Value("float64"),
"word_freq_internet": datasets.Value("float64"),
"word_freq_order": datasets.Value("float64"),
"word_freq_mail": datasets.Value("float64"),
"word_freq_receive": datasets.Value("float64"),
"word_freq_will": datasets.Value("float64"),
"word_freq_people": datasets.Value("float64"),
"word_freq_report": datasets.Value("float64"),
"word_freq_addresses": datasets.Value("float64"),
"word_freq_free": datasets.Value("float64"),
"word_freq_business": datasets.Value("float64"),
"word_freq_email": datasets.Value("float64"),
"word_freq_you": datasets.Value("float64"),
"word_freq_credit": datasets.Value("float64"),
"word_freq_your": datasets.Value("float64"),
"word_freq_font": datasets.Value("float64"),
"word_freq_000": datasets.Value("float64"),
"word_freq_money": datasets.Value("float64"),
"word_freq_hp": datasets.Value("float64"),
"word_freq_hpl": datasets.Value("float64"),
"word_freq_george": datasets.Value("float64"),
"word_freq_650": datasets.Value("float64"),
"word_freq_lab": datasets.Value("float64"),
"word_freq_labs": datasets.Value("float64"),
"word_freq_telnet": datasets.Value("float64"),
"word_freq_857": datasets.Value("float64"),
"word_freq_data": datasets.Value("float64"),
"word_freq_415": datasets.Value("float64"),
"word_freq_85": datasets.Value("float64"),
"word_freq_technology": datasets.Value("float64"),
"word_freq_1999": datasets.Value("float64"),
"word_freq_parts": datasets.Value("float64"),
"word_freq_pm": datasets.Value("float64"),
"word_freq_direct": datasets.Value("float64"),
"word_freq_cs": datasets.Value("float64"),
"word_freq_meeting": datasets.Value("float64"),
"word_freq_original": datasets.Value("float64"),
"word_freq_project": datasets.Value("float64"),
"word_freq_re": datasets.Value("float64"),
"word_freq_edu": datasets.Value("float64"),
"word_freq_table": datasets.Value("float64"),
"word_freq_conference": datasets.Value("float64"),
"char_freq_;": datasets.Value("float64"),
"char_freq_(": datasets.Value("float64"),
"char_freq_[": datasets.Value("float64"),
"char_freq_!": datasets.Value("float64"),
"char_freq_$": datasets.Value("float64"),
"char_freq_#": datasets.Value("float64"),
"capital_run_length_average": datasets.Value("float64"),
"capital_run_length_longest": datasets.Value("float64"),
"capital_run_length_total": datasets.Value("float64"),
"is_spam": 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 SpambaseConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(SpambaseConfig, self).__init__(version=VERSION, **kwargs)
self.features = features_per_config[kwargs["name"]]
class Spambase(datasets.GeneratorBasedBuilder):
# dataset versions
DEFAULT_CONFIG = "spambase"
BUILDER_CONFIGS = [
SpambaseConfig(name="spambase",
description="Spambase 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