load_upsell_bank_telemarketing#

empulse.datasets.load_upsell_bank_telemarketing(*, backend)[source]#

Load the bank telemarketing dataset (binary classification).

The goal is to predict whether a client will subscribe to a term deposit after being called by the bank. The target variable is whether the client subscribed, ‘yes’ = 1 and ‘no’ = 0.

Features recorded after the contact event are excluded to avoid data leakage. Only clients with a positive balance are considered.

For a full data description and additional information about the dataset, consult the User Guide.

Classes

2

Subscribers

4787

Non-subscribers

33144

Samples

37931

Features

10

Parameters:
backendmodule

Dataframe library to use for data and target. Pass the library module directly, e.g. backend=polars or backend=pandas.

Returns:
datasetDataset

instance_costs contains {'balance': array} — the client’s average yearly balance in euros, which drives the false-negative cost.

Notes

Cost matrix

Actual positive \(y_i = 1\)

Actual negative \(y_i = 0\)

Predicted positive \(\hat{y}_i = 1\)

tp_cost \(= c\)

fp_cost \(= c\)

Predicted negative \(\hat{y}_i = 0\)

fn_cost \(= \max(r \cdot d \cdot balance_i,\; c)\)

tn_cost \(= 0\)

The cost matrix uses symbolic parameters with the following defaults:

  • interest_rate (\(r\)) = 0.02463333

  • term_deposit_fraction (\(d\)) = 0.25

  • contact_cost (\(c\)) = 1.0

To override these defaults, pass the desired values when evaluating the metric:

metric(dataset.target, y_score, interest_rate=0.03, **dataset.instance_costs)

References

[1]

Moro, S., Rita, P., & Cortez, P. (2014). Bank Marketing [Dataset]. UCI Machine Learning Repository. https://doi.org/10.24432/C5K306.

Examples

import numpy as np
import pandas as pd
from empulse.datasets import load_upsell_bank_telemarketing
from empulse.metrics import Metric, Cost

dataset = load_upsell_bank_telemarketing(backend=pd)

# replace with your own model's predicted probabilities
y_score = np.random.default_rng(0).uniform(size=len(dataset.target))

metric = Metric(dataset.cost_matrix, Cost())
score = metric(dataset.target, y_score, **dataset.instance_costs)