cleverly.datasets.make_weekly_orders#

cleverly.datasets.make_weekly_orders(n: int, *, seed: int | Generator | None = None, backend: Literal['pandas', 'polars'] | str | None = None) → tuple[Any, dict[str, float]][source]#

Draw a three-week offer campaign with a weekly order, as a wide frame with exact truths.

Each week the retailer’s scoring system decides whether to send the customer a free-shipping code, and the order of that week is recorded. The frame has one row per customer.

Parameters:
nint

Number of customers.

seedint, Generator, or None

Seed or NumPy random generator.

backend{“pandas”, “polars”, “pyarrow”} or None, default=None

Dataframe backend. None uses pandas when installed, then the first available backend.

Returns:
framedataframe

A wide frame with the columns tenure, order_0, and, for each week t from 1 to 3 in time order, engaged_t, offer_t, tracked_t and order_t. tracked_t = 0 sets order_t and every later column to missing.

truthdict of str to float

The result of weekly_orders_truth().

See also

weekly_orders_truth

The exact truths this function returns.

weekly_orders_protocol

The protocol of the question the frame answers.

cleverly.Repeated

The outcome declaration that reads order_1 to order_3.

Notes

The law, for weeks \(t = 1, 2, 3\), with \(L_t\) engagement, \(A_t\) the offer, \(C_t\) staying tracked, and \(Y_t\) the order of week \(t\):

variable

law

tenure \(W\)

0, 1 or 2 (under a year, one to two years, longer), each 1/3

order_0 \(Y_0\)

Bernoulli, logit \(-0.4 + 0.4 W\)

engaged_1

Bernoulli, logit \(-0.3 + 0.4 W + 0.8 Y_0\)

engaged_t, t >= 2

Bernoulli, logit \(-0.7 + 0.3 W + 1.1 L_{t-1} + 0.7 A_{t-1} + 0.8 Y_{t-1}\)

offer_t

Bernoulli, logit \(0.8 + 0.1 W - 0.4 L_t - 1.4 Y_{t-1} + 0.2 A_{t-1}\)

tracked_t

Bernoulli, logit \(2.8 + 0.2 W + 0.4 L_t - 0.5 A_t\)

order_t

Bernoulli, logit \(-1.5 + 0.3 W + 1.0 L_t + 0.9 A_t + 1.2 Y_{t-1} - 0.7 A_t A_{t-1}\)

\(A_0 = L_0 = 0\). Last week’s order lowers the chance of an offer and raises the chance of an order, so it confounds each later offer. Tracking loss reads the week’s record and offer, never the week’s order, so it is missing at random given the history.

Examples

>>> from cleverly.datasets import make_weekly_orders
>>> frame, truth = make_weekly_orders(200, seed=0)
>>> list(frame.columns)[:6]
['tenure', 'order_0', 'engaged_1', 'offer_1', 'tracked_1', 'order_1']
>>> round(truth["ate_regimen[win_back vs never @ t=2]"], 3)
0.089