make_retail_events#
- skrub.datasets.make_retail_events(n_users=200, n_events=5000, random_state=None)[source]#
Generate a synthetic e-commerce clickstream dataset for classification.
Each row represents one user interaction event on a retail platform. The dataset is designed to showcase
SessionEncoder(which groups events into sessions usinguser_idandtimestamp),DatetimeEncoder(which extracts hour-of-day, day-of-week, etc. fromtimestamp), one-hot encoding of categorical features, and scaling of numerical features.The binary target
convertedindicates whether a purchase occurred during the session that contains this event. All events belonging to the same session share the sameconvertedvalue (a session either converts or it does not). The probability of conversion is determined at the session level by the most intent-rich event type in the session (add_to_cart>wishlist>search>page_view), the dominant device, and the mean price viewed — so the signal is learnable directly from the observable features.- Parameters:
- n_users
int, default=200 Number of distinct users in the dataset.
- n_events
int, default=5000 Approximate total number of events (rows) to generate. The actual count may differ slightly because session sizes are drawn from a Poisson distribution.
- random_state
intorRandomStateinstance, optional Controls the random number generation for reproducibility.
- n_users
- Returns:
- bunch
Bunch A dictionary-like object with the following attributes:
X:DataFramewith columns:user_id: str — user identifier.timestamp:Timestamp— event time.device_type: str — one of"mobile","desktop","tablet".page_category: str — one of"electronics","fashion","home","sports","books".event_type: str — one of"page_view","search","add_to_cart","wishlist".time_on_page: float — seconds spent on the page (exponential distribution, mean ~ 120 s).price_viewed: float — price of the item viewed (log-normal).
y:Seriesof bool, name"converted"— the classification target.
- bunch
Examples
>>> from skrub.datasets import make_retail_events >>> bunch = make_retail_events(n_users=20, n_events=100, random_state=0) >>> bunch.X.shape[1] # 7 feature columns; rows ~ n_events 7 >>> bunch.X.columns.tolist() ['user_id', 'timestamp', 'device_type', 'page_category', 'event_type', 'time_on_page', 'price_viewed'] >>> bunch.y.name 'converted' >>> bunch.y.dtype dtype('bool')
Gallery examples#
Sessions in time-based data: Predicting user purchases with the SessionEncoder