Generate Synthetic Clickstream Data with Python Function
Problem Description
The analytics team requires a method to generate synthetic click-stream records. These records are crucial for thoroughly testing a new reporting pipeline before it goes live and receives real user traffic.
Task
Implement a Python function, simulate_clickstream(num_users: int, days: int), that generates and returns a Pandas DataFrame. This DataFrame should represent simulated user events and must include the following columns: user_id, event_ts, page, and clicked.
Constraints and Specifications
- Timestamping: All generated events must have timestamps falling within the past
daysdays from the current execution time. - Page Visits: Each simulated user should visit a random number of pages per day, ranging from 1 to 10.
- Click Probability: For every page visit, there is a 0.15 probability that the
clickedcolumn will beTrue(or 1), otherwiseFalse(or 0). - Tools: Consider using
numpy.randomfor generating random page counts and probabilities. A common approach is to build a list of dictionaries, where each dictionary represents an event, and then convert this list into a Pandas DataFrame.
AI interview prep
Core dilemma
Balancing the efficient generation of a large volume of structured synthetic data with the need for realistic random distributions and managing memory/computational resources within a single process.
3 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Generate Synthetic Clickstream Data with Python Function
Problem Description
The analytics team requires a method to generate synthetic click-stream records. These records are crucial for thoroughly testing a new reporting pipeline before it goes live and receives real user traffic.
Task
Implement a Python function, simulate_clickstream(num_users: int, days: int), that generates and returns a Pandas DataFrame. This DataFrame should represent simulated user events and must include the following columns: user_id, event_ts, page, and clicked.
Constraints and Specifications
- Timestamping: All generated events must have timestamps falling within the past
daysdays from the current execution time. - Page Visits: Each simulated user should visit a random number of pages per day, ranging from 1 to 10.
- Click Probability: For every page visit, there is a 0.15 probability that the
clickedcolumn will beTrue(or 1), otherwiseFalse(or 0). - Tools: Consider using
numpy.randomfor generating random page counts and probabilities. A common approach is to build a list of dictionaries, where each dictionary represents an event, and then convert this list into a Pandas DataFrame.