Penrose Particles · Data methods / 01

Can synthetic shopping sessions preserve real browsing patterns?

A Bayesian network generates sessions from a public ecommerce dataset. The synthetic sample is compared with original records that were held out when fitting the model.

Purchase rate by segment

Held-out real Synthetic

Segment proportions

How often each segment occurs in each dataset. Select a field on the left.

Held-out real Synthetic

Generation model

Each variable is sampled from a probability table conditioned on its listed parents. Categories are grouped before fitting, and smoothing is applied to the probability tables.

Month → Visitor type Month → Traffic type Visitor + traffic → Product pages Product pages + visitor → Exit band Product pages + exit + traffic → Purchase
This graph describes how the synthetic records were generated. It does not establish that changing a variable would cause a change in purchases. Synthetic sessions are not actual customers.

Reading the results

The model was fitted on 80% of the 12,330 source sessions. The remaining 20% were held out for comparison. A fixed random seed of 2419 was used. Bars show descriptive rates; small groups may vary substantially.

How I made the synthetic data

  1. Prepared the original data

    I started with 12,330 online shopping sessions from the UCI dataset. I selected six fields: month, visitor type, traffic type, product pages viewed, exit rate, and whether a purchase occurred. I grouped page counts and exit rates into ranges.

  2. Kept some sessions aside

    I used 9,864 sessions to build the model. I held back the other 2,466 sessions so I could check the results against data the model had not used.

  3. Built a Bayesian network

    I chose which fields the model would use to predict each next field. For example, it uses visitor type and traffic type when generating the number of product pages viewed. It learns the probabilities for those combinations from the training sessions.

  4. Generated new sessions

    The model sampled those probabilities to create 2,466 synthetic sessions. These are newly generated records, not copies of the original shoppers.

  5. Checked the results

    I compared the synthetic sessions with the held-out sessions: their overall purchase rates, the sizes of different visitor groups, and purchase rates within those groups. Some groups matched more closely than others.

The network describes patterns in this dataset. It does not prove that changing a visitor's traffic source or browsing behavior would cause them to make a purchase.

Download the Python code used for this study →