Pulse Data Hub

Data Science in Marketing: A Bank Campaign Model, Tested

Data Science in Marketing: A Bank Campaign Model, Tested

Data science in marketing is mostly a targeting problem: who should you contact, and who should you leave alone? This article tests it on 41,188 real phone calls from a bank’s term-deposit campaign. We measure how much a model improves targeting, why one popular feature makes the results look better than they could ever be, and how the answer changes when we count the cost of calls. All results use scikit-learn 1.9.1 and pandas 3.0.5.

Bar chart: calling 20% at random reaches about 20% of subscribers, an honest model 67.0%, a model using call length 89.2%
Calling the top 20% of customers by model score, versus calling 20% at random.

The data

The data is the UCI Bank Marketing dataset: 41,188 calls by a Portuguese bank, with customer details, campaign history and economic indicators. 4,640 customers (11.27%) subscribed. The rows are in time order, so we trained on the first 80% (32,950 calls) and tested on the last 20% (8,238), which mimics predicting the future. The test set has 10.7% subscribers against 11.4% in training.

import pandas as pd
d = pd.read_csv('banking.csv')
print(d.shape, d.y.mean())          # (41188, 21)  0.1127

n = int(len(d) * 0.8)
train, test = d.iloc[:n], d.iloc[n:]   # time-ordered split, no shuffling

What the raw data says

Customers who had already said yes to an earlier campaign subscribed 65.1% of the time (1,373 customers), against 8.8% for customers never contacted before. Calls to mobiles subscribed 14.7% against 5.2% for landlines. Success fell with every extra call in the same campaign: 13.0% on the first, 11.5% on the second and 3.6% by the tenth. By job, students (31.4%) and retired customers (25.2%) subscribed most, blue-collar workers (6.9%) least. March, December, September and October had the highest rates, but those months also have far fewer calls (182 to 718), so we treat them cautiously.

The feature that makes results look too good

The dataset includes duration, the length of the call in seconds. Subscribers talked for a median of 449 seconds against 163 for non-subscribers. A boosting model that uses it scored a ROC AUC of 0.950 on the test set, and calling the top 20% reached 89.2% of subscribers. But call length is only known after the call, so you cannot use it to decide whom to call. This is data leakage, and the UCI documentation itself says duration should be left out of a realistic model. Without it, AUC fell to 0.806 and the top 20% reached 67.0%. Logistic regression gave 0.933 with duration and 0.791 without.

from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.pipeline import make_pipeline

# one-hot encode categoricals, standardize numbers, drop 'duration'
model = make_pipeline(preprocess_without_duration, HistGradientBoostingClassifier(random_state=0))
model.fit(train.drop(columns='y'), train.y)
score = model.predict_proba(test.drop(columns='y'))[:, 1]   # AUC 0.806

How much does targeting help?

Model, test setAUCSubscribers in top 10% / 20% / 30%
Boosting, honest (no duration)0.80645.4% / 67.0% / 73.3%
Logistic regression, honest0.79145.2% / 63.6% / 70.6%
Boosting with duration (leaky)0.95059.0% / 89.2% / 98.1%
Random calling0.50010% / 20% / 30%

With the honest model, calling the top 10% of customers by score reached 45% of all subscribers, more than four times the random rate. A random 80/20 split gave a similar AUC (0.797), so the time-ordered test was not unusually hard.

Counting the cost of calls

Targeting only pays if the saving on calls beats the lost sales. As an illustration, we assumed each call costs 5 and each subscription earns 50 (made-up round numbers, not the bank’s figures). Calling all 8,238 test customers gives a profit of 3,060. Calling only the top 10% (823 calls) reaches 402 subscribers for a profit of 15,985; the top 20% (1,647 calls) gives 593 subscribers and 21,415, the best of the cut-offs we tried; the top 30% gives 20,095 and the top 50% 15,805. Calling everyone is the worst option in this example. The best cut-off depends entirely on your costs and margin, so recompute it with your own numbers.

Using this in practice

The same pattern applies to email campaigns, churn offers and ads: score customers, contact the top slice and measure the result with a holdout group. Keep the model honest by checking every feature is known at decision time, as with duration. See our guides to logistic regression, random forests and the scikit-learn workflow, and data science in retail for customer segmentation. The scikit-learn histogram gradient boosting documentation covers the model used.

Limits of this analysis

One bank and one campaign from 2008 to 2010 in Portugal; a single time split; no hyperparameter tuning; economic indicators that describe the period, so the model may not carry to a different market. Costs and revenues are invented for illustration. The model predicts who subscribes, not who would only subscribe because of the call, which needs a controlled experiment.

FAQ

How is data science used in marketing?

To target the right customers, predict churn and response, personalise offers and measure campaigns. Here we scored customers for a term-deposit campaign.

Why not use call duration in the model?

Because it is only known after the call. Including it lifted AUC from 0.806 to 0.950 but would be impossible to use in practice.

How many customers should be contacted?

That depends on cost and margin. With our assumed numbers the top 20% gave the highest profit, but you must use your own figures.

Is the data real?

Yes, it is the public UCI Bank Marketing dataset linked above. The cost and profit figures are our assumptions.

Newsletter Signup Form

Latest tutorials

Latest articles

On this page
Verified by MonsterInsights