Visit-day events for lapse prediction
Task type: BinaryClassificationTask. This recipe adds an event source; it does not define a target. Keep your existing lapse, churn, retention, return or next-visit target, its positive-label meaning and its prediction horizon. Do not change the split points, cohort, temporal split dates or training settings.
Line-level retail transactions describe products, not shopping occasions. A ten-line shopping day becomes ten events in the transaction source. A second visits event source gives BaseModel one event per customer per day, so it can also learn the rhythm of shopping days. Keep the original transactions event source: the daily source supplements product detail rather than replacing it.
When to use this recipe
- Transactions contain multiple product lines for one customer on one day.
- The target concerns returning, lapsing, churn, retention or the next visit.
- For purchase propensity, consider this source when shopping cadence matters; it is optional, not a requirement for every propensity model.
- Do not add this aggregation by default when data already has one row per visit or order. A day may contain several visits or orders; a visit-day is not a reconstructed receipt or an individual store visit.
This recipe adds no customer snapshots, RFM attributes, profile source or synthetic split-point events. It changes the event representation only.
Build one event per customer and day
The public H&M example uses customer_id, the date column t_dat and line amount price. The input date already has day resolution. Aggregate the same eligible transaction rows that feed the original source:
SELECT
customer_id,
t_dat AS t_dat,
count(*) AS lines,
sum(price) AS spend,
count(*) AS units
FROM transactions
GROUP BY 1, 2;
Write this result to ./data/visits.parquet. There must be exactly one row per customer_id and t_dat. Here units is a line count, just like lines; it is not a sum of a quantity column. spend is the sum of the line amounts. Do not replace either count with distinct products or orders.
For another schema, substitute the entity, day, amount and table names. If the source has timestamps, first derive the business-calendar day consistently for both sources. Use the same entity IDs, transaction eligibility and day definition for the raw and daily events. Rebuild the daily source if those inputs change; do not attach totals from a different population or period.
Event-source configuration
Merge the root-level data_sources and data_params below into your FM YAML, preserving its other fields. Pass that file to pretrain(config_path=Path("fm_config.yaml"), output_path=Path("project/model")) as shown in Setup. The configuration shows both public H&M event sources and the required boundary rule. Paths are local examples. Keep your existing transaction source and any unrelated configuration. Add the visits entry to data_sources; do not replace that list with only the new source. The source names, entity column, day format and allowed_columns match the measured daily-event setup.
data_sources:
- type: event
name: transactions
main_entity_column: customer_id
date_column:
name: t_dat
format: '%Y-%m-%d'
allowed_columns: [article_id, price, sales_channel_id]
data_location:
database_type: parquet
connection_params:
path: ./data/transactions.parquet
cache_path: ./source-cache
table_name: transactions
- type: event
name: visits
main_entity_column: customer_id
date_column:
name: t_dat
format: '%Y-%m-%d'
allowed_columns: [lines, spend, units]
column_type_overrides:
lines: decimal
spend: decimal
units: decimal
data_location:
database_type: parquet
connection_params:
path: ./data/visits.parquet
cache_path: ./source-cache
table_name: visits
data_params:
history_future_split_overrides:
split_point_inclusion_overrides:
transactions: future
visits: future
The boundary day belongs to the future in both sources
For a split point T on a day boundary, history contains days strictly before T. Events on the boundary day go to the future in both transactions and visits. This is an input-history rule; it does not change which future events your existing target labels or its horizon.
Setting only transactions: future is not enough. If the same day's visits row remains in history, its lines, spend and units expose purchases from the boundary day. Setting only visits: future leaves the raw lines exposed. Both overrides prevent that boundary-day leakage. Preserve all other existing overrides, split points and split dates.
Keep the prediction task and training unchanged
Use the same target function, horizon, label convention, eligible customers, split-point sampling, temporal splits and training settings as the baseline. No target defaults, split dates, model size or training schedule are supplied by this recipe. Pass the augmented event sources to foundation-model training, and keep the existing task configuration. The extra source naturally changes the input size; it is not a reason to change the task or tune on held-out data.
For a small workflow check, use the same small customer subset for both sources. Then restore the original eligible population. Compare the baseline and augmented setup on the same held-out customers and origins. Do not use the added source to alter target eligibility or select easier customers.
Measured effect on public H&M data
In a public H&M lapse experiment, adding this daily event source was the only data change. The target, split points and training settings stayed unchanged. Compared with plain BaseModel:
- Test average precision (AP) increased by 0.0044, with a paired 95% customer-bootstrap interval of [0.0035, 0.0053].
- Confirm AP increased by 0.0067.
- Test AUROC exceeded XGBoost by 0.001240, with a paired 95% interval of [0.000248, 0.002119].
These comparisons used one fit per setup. The intervals describe customer resampling conditional on those fits; they do not measure retraining uncertainty or include a multiple-comparison correction. Ranking improved, but capture at the top 10% was still below the tuned trees on test; the confirm comparison favored the daily-event model. Do not infer a guaranteed campaign gain.
In a separate five-seed H&M benchmark protocol, visit-day BaseModel achieved mean test AP 0.6330, versus 0.6361 for tuned XGBoost: 99.5% of the tree score, not a win. The remaining difference was measurable. Do not combine this protocol's scores with the single-fit intervals above.
The motivation is shopping cadence. In the original H&M analysis, much of the net tree advantage was concentrated among the rarest buyers. This is a descriptive segment observation, not a causal claim or evidence that every churn or propensity dataset needs daily events.