Hereβs a concise and informative README.md for your script:
This project simulates user interactions with product recommendation algorithms using multi-armed bandit strategiesβThompson Sampling, Upper Confidence Bound (UCB), and Random Selectionβto evaluate which algorithm drives more user engagement (clicks).
The goal is to simulate and analyze how different recommendation algorithms perform in driving user selections from various product divisions. It seeks to answer:
- Does the algorithm type affect user decisions?
- Is there a statistically significant difference in engagement between algorithms?
The simulation comprises the following stages:
- Reads product data from
Items_without_duplicates.csv. - Extracts product divisions (categories).
- Creates a list of
Userobjects from auser_dataclass, initializing internal tracking for each algorithm.
For each algorithm:
- Runs multiple trials for each user.
- In each trial:
- Recommends a division based on the algorithm.
- Uses bias-based acceptance to simulate user behavior.
- Updates internal tracking stats (clicks, impressions).
- Performs a Chi-Squared Test to assess if user engagement varies by algorithm.
- Conducts a T-Test to determine if there's a statistically significant difference in click rates between UCB and Thompson Sampling.
- Total clicks generated by each algorithm.
True/Falseindicating whether the algorithm type significantly impacts user behavior.True/Falseindicating whether there's a significant difference between Thompson and UCB.
initialize_user_collection(...): Initializes users for each algorithm group.generate_interaction_data_from_multiple_runs(...): Simulates user trials and updates user state.check_if_algorithm_type_affects_user_decisions(...): Chi-squared test for independence.check_for_significant_difference_between_clicks_due_to_algo_type(...): T-test for difference of means.
Make sure to have the following:
Items_without_duplicates.csv(Product data with at leastdept_nameandprod_namecolumns)user_dataclass implementation- Utility functions in
utils.py:recommendation_by_thompsonrecommendation_by_ucbrecommendation_by_randomget_division_probabilitieschi_squared_test_for_independencet_test_for_difference_of_means