fetch_telco_customer_churn#
- empulse.datasets.fetch_telco_customer_churn(*, backend, data_home=None, download_if_missing=True)[source]#
Fetch the Telco Customer Churn dataset from OpenML (binary classification).
The goal is to predict whether a customer will churn or not. The target variable is whether the customer churned, 1 = churned, 0 = active.
For additional information about the dataset, consult the User Guide.
Classes
2
Churners
1869
Non-churners
5163
Samples
7032
Features
19
- Parameters:
- backendmodule
Dataframe library to use for
dataandtarget. Pass the library module directly, e.g.backend=polarsorbackend=pandas.- data_homestr or Path, optional
Directory used for caching downloaded data. Defaults to
~/empulse_data(or$EMPULSE_DATA_HOME).- download_if_missingbool, default=True
If False, raise an
OSErrorwhen the data is not cached locally.
- Returns:
- dataset
Dataset instance_costscontains{'monthly_charges': array}— the customer’s monthly bill amount, which scales the false-negative and false-positive costs.
- dataset
Notes
Cost matrix (Petrides & Verbeke 2021, Vanderschueren et al. 2022):
Actual positive \(y_i = 1\)
Actual negative \(y_i = 0\)
Predicted positive \(\hat{y}_i = 1\)
tp_cost\(= 0\)fp_cost\(= fp\_months \cdot monthly\_charges_i\)Predicted negative \(\hat{y}_i = 0\)
fn_cost\(= fn\_months \cdot monthly\_charges_i\)tn_cost\(= 0\)The cost matrix uses symbolic parameters with the following defaults:
fn_months= 12.0 (annual revenue lost upon churn)fp_months= 2.0 (two months of retention offer cost)
References
[1]Petrides, G., & Verbeke, W. (2021). Cost-sensitive ensemble learning: a unifying framework. Data Mining and Knowledge Discovery, 1–28.
[2]Vanderschueren, T., Verdonck, T., Baesens, B., & Verbeke, W. (2022). Predict-then-optimize or predict-and-optimize? An empirical evaluation of cost-sensitive learning strategies. Information Sciences, 594, 400–415.
Examples
import numpy as np import pandas as pd from empulse.datasets import fetch_telco_customer_churn from empulse.metrics import Metric, Cost dataset = fetch_telco_customer_churn(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)