Dataset Viewer
The dataset viewer is not available for this dataset.
Unexpected token '<', "<html> <h"... is not valid JSON

Need help to make the dataset viewer work? Make sure to review how to configure the dataset viewer, and open a discussion for direct support.

Dataset Card for Bank Marketing

This dataset is a precise version of Bank Marketing.

To download the original csv from UCI

wget https://archive.ics.uci.edu/static/public/222/bank+marketing.zip
find . -name "*.zip" -exec sh -c 'unzip -d "${1%.*}" "$1" && rm "$1"' _ {} \;
find . -name "*.zip" -exec sh -c 'unzip -d "${1%.*}" "$1" && rm "$1"' _ {} \;

We used the following python script to create this Hugging Face dataset

import pandas as pd
df_bank = pd.read_csv("bank+marketing/bank/bank-full.csv", sep=";")
df_additional = pd.read_csv("bank+marketing/bank-additional/bank-additional/bank-additional-full.csv", sep=";")

df_bank["pdays"] = df_bank["pdays"].replace(-1, 999)


# Correct order for months and weekdays
correct_month_order = ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
                       'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
correct_weekday_order = ['mon', 'tue', 'wed', 'thu', 'fri']

# List of categorical columns
categorical_columns = ["job", "marital", "education", "default", "housing", "loan",
                       "contact", "month", "poutcome", "y"]

# Create a reference mapping from bank-additional (since it has more features)
bank_categories = {
    col: list(df_bank[col].astype("category").cat.categories)
    for col in categorical_columns
}

# Manually enforce correct month and weekday order
bank_categories["month"] = correct_month_order

# Create a reference mapping from bank-additional (since it has more features)
bank_additional_categories = {
    col: list(df_additional[col].astype("category").cat.categories)
    for col in categorical_columns
}

# Manually enforce correct month and weekday order
bank_additional_categories["month"] = correct_month_order
# bank_additional_categories["day_of_week"] = correct_weekday_order


from collections import OrderedDict

# Merge dictionaries using set union, preserving order where needed
reference_categories = {
    key: list(OrderedDict.fromkeys(bank_categories.get(key, []) + bank_additional_categories.get(key, [])))
    for key in set(bank_categories) | set(bank_additional_categories)
}

# Extract category mappings from the reference dataset (bank-additional)
category_mappings = {col: reference_categories[col] for col in categorical_columns}

from datasets import Dataset, DatasetDict, Features, Value, ClassLabel

# Define Hugging Face dataset schema
hf_features = Features({
    "age": Value("int64"),
    "job": ClassLabel(names=category_mappings["job"]),
    "marital": ClassLabel(names=category_mappings["marital"]),
    "education": ClassLabel(names=category_mappings["education"]),
    "default": ClassLabel(names=category_mappings["default"]),
    "balance": Value("int64"),
    "housing": ClassLabel(names=category_mappings["housing"]),
    "loan": ClassLabel(names=category_mappings["loan"]),
    "contact": ClassLabel(names=category_mappings["contact"]),
    "day": Value("int64"),
    "month": ClassLabel(names=category_mappings['month']),
    "duration": Value("int64"),
    "campaign": Value("int64"),
    "pdays": Value("int64"),
    "previous": Value("int64"),
    "poutcome": ClassLabel(names=category_mappings["poutcome"]),
    "y": ClassLabel(names=category_mappings["y"])  # Target column
})


# Create a dataset dictionary
hf_dataset = DatasetDict({
    "train": Dataset.from_pandas(df_bank, features=hf_features),
})

# Print dataset structure
print(hf_dataset)

The printed output could look like

DatasetDict({
    train: Dataset({
        features: ['age', 'job', 'marital', 'education', 'default', 'balance', 'housing', 'loan', 'contact', 'day', 'month', 'duration', 'campaign', 'pdays', 'previous', 'poutcome', 'y'],
        num_rows: 45211
    })
})

Note that there is an additional file bank+marketing/bank-additional/bank-additional/bank-additional-full.csv which contains 4 more columns. To avoid unnecessary errors, we align the categories from both datasets. We have also created a Hugging Face dataset for this additional data (HERE).

Downloads last month
462

Space using cestwc/bank-marketing 1