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:
- Returns:
- frame
dataframe A wide frame with the columns
tenure,order_0, and, for each weektfrom 1 to 3 in time order,engaged_t,offer_t,tracked_tandorder_t.tracked_t = 0setsorder_tand every later column to missing.- truth
dictofstrtofloat The result of
weekly_orders_truth().
- frame
See also
weekly_orders_truthThe exact truths this function returns.
weekly_orders_protocolThe protocol of the question the frame answers.
cleverly.RepeatedThe outcome declaration that reads
order_1toorder_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_1Bernoulli, logit \(-0.3 + 0.4 W + 0.8 Y_0\)
engaged_t, t >= 2Bernoulli, logit \(-0.7 + 0.3 W + 1.1 L_{t-1} + 0.7 A_{t-1} + 0.8 Y_{t-1}\)
offer_tBernoulli, logit \(0.8 + 0.1 W - 0.4 L_t - 1.4 Y_{t-1} + 0.2 A_{t-1}\)
tracked_tBernoulli, logit \(2.8 + 0.2 W + 0.4 L_t - 0.5 A_t\)
order_tBernoulli, 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