{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["### Generate Group Of Bundle Based On Tags And Specs"],"metadata":{"id":"VUTSHmhQhbVe"}},{"cell_type":"code","source":["import re\n","import numpy as np\n","\n","def remove_currency_symbol(price_str):\n"," \"\"\"Removes currency symbols ($, £, €, etc.) from a price string.\n","\n"," Args:\n"," price_str: The price string to clean.\n","\n"," Returns:\n"," The cleaned price string without currency symbols, or None if no numeric part is found.\n"," \"\"\"\n"," # Use a regular expression to find any numeric part of the string, allowing for decimal points\n"," match = re.search(r\"[-+]?\\d*\\.?\\d+\", price_str)\n"," if match:\n"," return float(match.group(0))\n"," else:\n"," return 0.0"],"metadata":{"id":"sT4b3MlpQUkp"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# prompt: Load data from /content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/bundle_data.json.gz using json\n","\n","import json\n","import gzip\n","import ast\n","\n","# Open the gzipped file\n","bundle_data = {}\n","data_dict = None\n","item_dict = None\n","count = {\n"," \"bundles\": 0,\n"," \"items\": 0\n","}\n","\n","file_path = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/bundle_data.json.gz\"\n","\n","with gzip.open(f\"{file_path}\", 'rt', encoding='utf-8') as f: # 'rt' is for text mode\n"," for i, line in enumerate(f):\n"," # Remove the trailing newline character\n"," cleaned_string = line.strip()\n"," try:\n"," data_dict = ast.literal_eval(cleaned_string)\n"," count[\"items\"] += len(data_dict[\"items\"])\n"," count[\"bundles\"] += 1\n","\n"," item_dict = set()\n"," for item in data_dict[\"items\"]:\n"," item_dict.add(item[\"item_id\"])\n","\n"," bundle_data[data_dict['bundle_id']] = {\n"," \"bundle_id\": data_dict['bundle_id'],\n"," \"bundle_price\": remove_currency_symbol(data_dict['bundle_price']),\n"," \"bundle_name\": data_dict['bundle_name'],\n"," \"items\": item_dict\n"," }\n"," except (ValueError, SyntaxError) as e:\n"," print(f\"Failed to convert string to dictionary: {e}\")\n","\n","print(f\"Number of bundle {count['bundles']}\")\n","print(f\"Number of items {count['items']}\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"rrq-gfhdNyLM","executionInfo":{"status":"ok","timestamp":1736565019812,"user_tz":-420,"elapsed":1346,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"dbde2bba-ce6a-43d5-c1d0-d358a801b3a2"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Number of bundle 615\n","Number of items 3525\n"]}]},{"cell_type":"code","source":["# prompt: Load data from /content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/steam_games.json.gz\n","\n","import json\n","import gzip\n","\n","file_path = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/steam_games.json.gz\"\n","\n","# Open the gzipped file\n","items_dictionary = {}\n","data_dict = None\n","count = {\n"," \"items\": 0\n","}\n","with gzip.open(f\"{file_path}\", 'rt', encoding='utf-8') as f: # 'rt' is for text mode\n"," for i, line in enumerate(f):\n"," # Remove the trailing newline character\n"," cleaned_string = line.strip()\n"," try:\n"," data_dict = ast.literal_eval(cleaned_string)\n"," if 'id' in data_dict:\n"," items_dictionary[data_dict['id']] = data_dict\n"," count[\"items\"] += 1\n"," except (ValueError, SyntaxError) as e:\n"," print(f\"Failed to convert string to dictionary: {e}\")\n","\n","print(f\"Number of items {count['items']}\")\n","print(data_dict)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"I-dDe4UNQaw7","executionInfo":{"status":"ok","timestamp":1736565024041,"user_tz":-420,"elapsed":4230,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"ab08b6be-819e-4ca1-ac91-8b4c361a32dc"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Number of items 32133\n","{'app_name': 'Maze Run VR', 'sentiment': 'Positive', 'tags': ['Early Access', 'Adventure', 'Indie', 'Action', 'Simulation', 'VR'], 'url': 'http://store.steampowered.com/app/681550/Maze_Run_VR/', 'price': 4.99, 'reviews_url': 'http://steamcommunity.com/app/681550/reviews/?browsefilter=mostrecent&p=1', 'id': '681550', 'early_access': True, 'specs': ['Single-player', 'Stats', 'Steam Leaderboards', 'HTC Vive', 'Oculus Rift', 'Tracked Motion Controllers', 'Standing', 'Room-Scale']}\n"]}]},{"cell_type":"code","source":["# Open the gzipped file\n","user_item_interactions = {}\n","data_dict = None\n","count = {\n"," \"users\": 0,\n"," \"items\": 0\n","}\n","\n","file_path = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/australian_users_items.json.gz\"\n","\n","with gzip.open(f\"{file_path}\", 'rt', encoding='utf-8') as f: # 'rt' is for text mode\n"," for i, line in enumerate(f):\n"," # Remove the trailing newline character\n"," cleaned_string = line.strip()\n"," try:\n"," data_dict = ast.literal_eval(cleaned_string)\n"," if data_dict[\"items_count\"] > 0:\n"," count[\"items\"] += data_dict[\"items_count\"]\n"," count[\"users\"] += 1\n","\n"," item_dict = set()\n"," for item in data_dict[\"items\"]:\n"," item_dict.add(item[\"item_id\"])\n","\n"," user_item_interactions[data_dict['user_id']] = {\n"," \"user_id\": data_dict['user_id'],\n"," \"items_count\": data_dict[\"items_count\"],\n"," \"items\": item_dict\n"," }\n"," except (ValueError, SyntaxError) as e:\n"," print(f\"Failed to convert string to dictionary: {e}\")\n","\n"," if count[\"users\"] == 10000:\n"," break\n","\n","print(f\"Number of user {count['users']}\")\n","print(f\"Number of items {count['items']}\")\n","print(data_dict)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"NvLqTlK-SOvG","executionInfo":{"status":"ok","timestamp":1736492310943,"user_tz":-420,"elapsed":42563,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"42e176aa-909f-4179-f929-9e32c65e8044"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Number of user 10000\n","Number of items 1132592\n","{'user_id': '76561198030000787', 'items_count': 314, 'steam_id': '76561198030000787', 'user_url': 'http://steamcommunity.com/profiles/76561198030000787', 'items': [{'item_id': '4000', 'item_name': \"Garry's Mod\", 'playtime_forever': 32, 'playtime_2weeks': 0}, {'item_id': '2600', 'item_name': 'Vampire: The Masquerade - Bloodlines', 'playtime_forever': 1, 'playtime_2weeks': 0}, {'item_id': '2200', 'item_name': 'Quake III Arena', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '2310', 'item_name': 'Quake', 'playtime_forever': 26, 'playtime_2weeks': 0}, {'item_id': '2320', 'item_name': 'Quake II', 'playtime_forever': 5, 'playtime_2weeks': 0}, {'item_id': '2330', 'item_name': 'Quake II: The Reckoning', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '2340', 'item_name': 'Quake II: Ground Zero', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '2350', 'item_name': 'Quake III: Team Arena', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '9030', 'item_name': 'Quake Mission Pack 2: Dissolution of Eternity', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '9040', 'item_name': 'Quake Mission Pack 1: Scourge of Armagon', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '4760', 'item_name': 'Rome: Total War', 'playtime_forever': 124, 'playtime_2weeks': 0}, {'item_id': '4770', 'item_name': 'Rome: Total War - Alexander', 'playtime_forever': 5, 'playtime_2weeks': 0}, {'item_id': '18500', 'item_name': 'Defense Grid: The Awakening', 'playtime_forever': 486, 'playtime_2weeks': 0}, {'item_id': '17460', 'item_name': 'Mass Effect', 'playtime_forever': 1896, 'playtime_2weeks': 0}, {'item_id': '1250', 'item_name': 'Killing Floor', 'playtime_forever': 949, 'playtime_2weeks': 0}, {'item_id': '35420', 'item_name': 'Killing Floor Mod: Defence Alliance 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21680', 'item_name': 'Bionic Commando Rearmed', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21670', 'item_name': 'Bionic Commando', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '38400', 'item_name': 'Fallout', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '38410', 'item_name': 'Fallout 2', 'playtime_forever': 1, 'playtime_2weeks': 0}, {'item_id': '38420', 'item_name': 'Fallout Tactics', 'playtime_forever': 48, 'playtime_2weeks': 0}, {'item_id': '20900', 'item_name': 'The Witcher: Enhanced Edition', 'playtime_forever': 38, 'playtime_2weeks': 0}, {'item_id': '17450', 'item_name': 'Dragon Age: Origins', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '10180', 'item_name': 'Call of Duty: Modern Warfare 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '10190', 'item_name': 'Call of Duty: Modern Warfare 2 - Multiplayer', 'playtime_forever': 835, 'playtime_2weeks': 0}, {'item_id': '550', 'item_name': 'Left 4 Dead 2', 'playtime_forever': 683, 'playtime_2weeks': 0}, {'item_id': '223530', 'item_name': 'Left 4 Dead 2 Beta', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '22370', 'item_name': 'Fallout 3 - Game of the Year Edition', 'playtime_forever': 3, 'playtime_2weeks': 0}, {'item_id': '24980', 'item_name': 'Mass Effect 2', 'playtime_forever': 1837, 'playtime_2weeks': 0}, {'item_id': '33910', 'item_name': 'Arma 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '33930', 'item_name': 'Arma 2: Operation Arrowhead', 'playtime_forever': 57, 'playtime_2weeks': 0}, {'item_id': '219540', 'item_name': 'Arma 2: Operation Arrowhead Beta (Obsolete)', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '22380', 'item_name': 'Fallout: New Vegas', 'playtime_forever': 5078, 'playtime_2weeks': 0}, {'item_id': '42700', 'item_name': 'Call of Duty: Black Ops', 'playtime_forever': 537, 'playtime_2weeks': 0}, {'item_id': '42710', 'item_name': 'Call of Duty: Black Ops - Multiplayer', 'playtime_forever': 2037, 'playtime_2weeks': 0}, {'item_id': '47810', 'item_name': 'Dragon Age: Origins - Ultimate Edition', 'playtime_forever': 1522, 'playtime_2weeks': 0}, {'item_id': '78000', 'item_name': 'Bejeweled 3', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '56400', 'item_name': 'Warhammer® 40,000™: Dawn of War® II – Retribution™', 'playtime_forever': 917, 'playtime_2weeks': 0}, {'item_id': '48720', 'item_name': 'Mount & Blade: With Fire and Sword', 'playtime_forever': 424, 'playtime_2weeks': 0}, {'item_id': '20920', 'item_name': 'The Witcher 2: Assassins of Kings Enhanced Edition', 'playtime_forever': 2141, 'playtime_2weeks': 0}, {'item_id': '105600', 'item_name': 'Terraria', 'playtime_forever': 1807, 'playtime_2weeks': 0}, {'item_id': '17430', 'item_name': 'Need for Speed: Undercover', 'playtime_forever': 2, 'playtime_2weeks': 0}, {'item_id': '24740', 'item_name': 'Burnout Paradise: The Ultimate Box', 'playtime_forever': 48, 'playtime_2weeks': 0}, {'item_id': '24870', 'item_name': 'Need for Speed: SHIFT', 'playtime_forever': 102, 'playtime_2weeks': 0}, {'item_id': '47870', 'item_name': 'Need for Speed: Hot Pursuit', 'playtime_forever': 211, 'playtime_2weeks': 0}, {'item_id': '47920', 'item_name': 'Shift 2 Unleashed', 'playtime_forever': 7, 'playtime_2weeks': 0}, {'item_id': '33440', 'item_name': 'Driver San Francisco', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '72850', 'item_name': 'The Elder Scrolls V: Skyrim', 'playtime_forever': 10060, 'playtime_2weeks': 0}, {'item_id': '91310', 'item_name': 'Dead Island', 'playtime_forever': 1853, 'playtime_2weeks': 0}, {'item_id': '111400', 'item_name': 'Bunch Of Heroes', 'playtime_forever': 167, 'playtime_2weeks': 0}, {'item_id': '45770', 'item_name': 'Dead Rising 2: Off the Record', 'playtime_forever': 206, 'playtime_2weeks': 0}, {'item_id': '102600', 'item_name': 'Orcs Must Die!', 'playtime_forever': 209, 'playtime_2weeks': 0}, {'item_id': '48220', 'item_name': 'Might & Magic: Heroes VI', 'playtime_forever': 1314, 'playtime_2weeks': 0}, {'item_id': '110800', 'item_name': 'L.A. Noire', 'playtime_forever': 243, 'playtime_2weeks': 0}, {'item_id': '16450', 'item_name': 'F.E.A.R. 2: Project Origin', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21000', 'item_name': 'LEGO Batman: The Videogame', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21010', 'item_name': 'Watchmen: The End Is Nigh', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21030', 'item_name': 'Watchmen: The End Is Nigh Part 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21070', 'item_name': 'Wanted: Weapons of Fate', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21080', 'item_name': 'Terminator Salvation', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21090', 'item_name': 'F.E.A.R.', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21100', 'item_name': 'F.E.A.R. 3', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21110', 'item_name': 'F.E.A.R.: Extraction Point', 'playtime_forever': 4, 'playtime_2weeks': 0}, {'item_id': '21120', 'item_name': 'F.E.A.R.: Perseus Mandate', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '21130', 'item_name': 'Lego Harry Potter', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32800', 'item_name': 'The Lord of the Rings: War in the North', 'playtime_forever': 64, 'playtime_2weeks': 0}, {'item_id': '35140', 'item_name': 'Batman: Arkham Asylum GOTY Edition', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '57400', 'item_name': 'Batman: Arkham City™', 'playtime_forever': 1924, 'playtime_2weeks': 0}, {'item_id': '107100', 'item_name': 'Bastion', 'playtime_forever': 36, 'playtime_2weeks': 0}, {'item_id': '200260', 'item_name': 'Batman: Arkham City GOTY', 'playtime_forever': 18, 'playtime_2weeks': 0}, {'item_id': '205790', 'item_name': 'Dota 2 Test', 'playtime_forever': 1, 'playtime_2weeks': 0}, {'item_id': '3900', 'item_name': \"Sid Meier's Civilization IV\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '3910', 'item_name': \"Sid Meier's Civilization III: Complete\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '3920', 'item_name': \"Sid Meier's Pirates!\", 'playtime_forever': 91, 'playtime_2weeks': 0}, {'item_id': '3990', 'item_name': \"Sid Meier's Civilization IV: Warlords\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '7650', 'item_name': 'X-COM: Terror from the Deep', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '7660', 'item_name': 'X-COM: Apocalypse', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '7670', 'item_name': 'BioShock', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '7730', 'item_name': 'X-COM: Interceptor', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '7760', 'item_name': 'X-COM: UFO Defense', 'playtime_forever': 27, 'playtime_2weeks': 0}, {'item_id': '7770', 'item_name': 'X-COM: Enforcer', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '8800', 'item_name': \"Sid Meier's Civilization IV: Beyond the Sword\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '8850', 'item_name': 'BioShock 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '8880', 'item_name': 'Freedom Force', 'playtime_forever': 98, 'playtime_2weeks': 0}, {'item_id': '8890', 'item_name': 'Freedom Force vs. the 3rd Reich', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '8930', 'item_name': \"Sid Meier's Civilization V\", 'playtime_forever': 1591, 'playtime_2weeks': 0}, {'item_id': '8970', 'item_name': 'Axel & Pixel', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '8980', 'item_name': 'Borderlands', 'playtime_forever': 12, 'playtime_2weeks': 0}, {'item_id': '16810', 'item_name': \"Sid Meier's Civilization IV: Colonization\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '34440', 'item_name': \"Sid Meier's Civilization IV\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '34450', 'item_name': \"Sid Meier's Civilization IV: Warlords\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '34460', 'item_name': \"Sid Meier's Civilization IV: Beyond the Sword\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '40920', 'item_name': 'NBA 2K10', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '40930', 'item_name': 'The Misadventures of P.B. Winterbottom', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '40990', 'item_name': 'Mafia', 'playtime_forever': 21, 'playtime_2weeks': 0}, {'item_id': '50130', 'item_name': 'Mafia II', 'playtime_forever': 300, 'playtime_2weeks': 0}, {'item_id': '50310', 'item_name': 'MLB 2K11', 'playtime_forever': 9, 'playtime_2weeks': 0}, {'item_id': '57900', 'item_name': 'Duke Nukem Forever', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '65950', 'item_name': 'NBA 2K11', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '201020', 'item_name': 'NBA 2K12', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '409710', 'item_name': 'BioShock Remastered', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '409720', 'item_name': 'BioShock 2 Remastered', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '67370', 'item_name': 'The Darkness II', 'playtime_forever': 146, 'playtime_2weeks': 0}, {'item_id': '207610', 'item_name': 'The Walking Dead', 'playtime_forever': 457, 'playtime_2weeks': 0}, {'item_id': '97330', 'item_name': 'Magic: The Gathering - Duels of the Planeswalkers 2013', 'playtime_forever': 300, 'playtime_2weeks': 0}, {'item_id': '65800', 'item_name': 'Dungeon Defenders', 'playtime_forever': 4376, 'playtime_2weeks': 0}, {'item_id': '211420', 'item_name': 'Dark Souls: Prepare to Die Edition', 'playtime_forever': 71, 'playtime_2weeks': 0}, {'item_id': '730', 'item_name': 'Counter-Strike: Global Offensive', 'playtime_forever': 1900, 'playtime_2weeks': 0}, {'item_id': '204300', 'item_name': 'Awesomenauts', 'playtime_forever': 584, 'playtime_2weeks': 0}, {'item_id': '200170', 'item_name': 'Worms Revolution', 'playtime_forever': 423, 'playtime_2weeks': 0}, {'item_id': '217200', 'item_name': 'Worms Armageddon', 'playtime_forever': 4, 'playtime_2weeks': 0}, {'item_id': '204360', 'item_name': 'Castle Crashers', 'playtime_forever': 614, 'playtime_2weeks': 0}, {'item_id': '49520', 'item_name': 'Borderlands 2', 'playtime_forever': 3393, 'playtime_2weeks': 0}, {'item_id': '216890', 'item_name': 'Blood Bowl: Chaos Edition', 'playtime_forever': 846, 'playtime_2weeks': 0}, {'item_id': '200510', 'item_name': 'XCOM: Enemy Unknown', 'playtime_forever': 715, 'playtime_2weeks': 0}, {'item_id': '4920', 'item_name': 'Natural Selection 2', 'playtime_forever': 10, 'playtime_2weeks': 0}, {'item_id': '220240', 'item_name': 'Far Cry® 3', 'playtime_forever': 1336, 'playtime_2weeks': 0}, {'item_id': '219740', 'item_name': \"Don't Starve\", 'playtime_forever': 4806, 'playtime_2weeks': 0}, {'item_id': '322330', 'item_name': \"Don't Starve Together\", 'playtime_forever': 2, 'playtime_2weeks': 0}, {'item_id': '220440', 'item_name': 'DmC Devil May Cry', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '226700', 'item_name': 'Infestation: Survivor Stories Classic', 'playtime_forever': 22, 'playtime_2weeks': 0}, {'item_id': '4540', 'item_name': 'Titan Quest', 'playtime_forever': 40, 'playtime_2weeks': 0}, {'item_id': '4550', 'item_name': 'Titan Quest: Immortal Throne', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '4560', 'item_name': 'Company of Heroes', 'playtime_forever': 136, 'playtime_2weeks': 0}, {'item_id': '9340', 'item_name': 'Company of Heroes: Opposing Fronts', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '9350', 'item_name': 'Supreme Commander', 'playtime_forever': 15, 'playtime_2weeks': 0}, {'item_id': '9420', 'item_name': 'Supreme Commander: Forged Alliance', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '9480', 'item_name': 'Saints Row 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '15620', 'item_name': 'Warhammer® 40,000™: Dawn of War® II', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '20530', 'item_name': 'Red Faction', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '20550', 'item_name': 'Red Faction II', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '20570', 'item_name': 'Warhammer® 40,000™: Dawn of War® II - Chaos Rising™', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '43110', 'item_name': 'Metro 2033', 'playtime_forever': 28, 'playtime_2weeks': 0}, {'item_id': '50620', 'item_name': 'Darksiders', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '50650', 'item_name': 'Darksiders II', 'playtime_forever': 1066, 'playtime_2weeks': 0}, {'item_id': '55100', 'item_name': 'Homefront', 'playtime_forever': 1, 'playtime_2weeks': 0}, {'item_id': '55110', 'item_name': 'Red Faction: Armageddon', 'playtime_forever': 15, 'playtime_2weeks': 0}, {'item_id': '55140', 'item_name': 'MX vs. ATV Reflex', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '55150', 'item_name': 'Warhammer 40,000 Space Marine', 'playtime_forever': 78, 'playtime_2weeks': 0}, {'item_id': '55230', 'item_name': 'Saints Row: The Third', 'playtime_forever': 1720, 'playtime_2weeks': 0}, {'item_id': '96800', 'item_name': 'Nexuiz', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '216370', 'item_name': 'Nexuiz Beta', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '225760', 'item_name': 'Nexuiz STUPID Mode', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '228200', 'item_name': 'Company of Heroes (New Steam Version)', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '475150', 'item_name': 'Titan Quest Anniversary Edition', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '228280', 'item_name': \"Baldur's Gate: Enhanced Edition\", 'playtime_forever': 481, 'playtime_2weeks': 0}, {'item_id': '11020', 'item_name': 'TrackMania Nations Forever', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '200210', 'item_name': 'Realm of the Mad God', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '205710', 'item_name': 'EverQuest Free-to-Play', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '207230', 'item_name': 'Archeblade', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '208090', 'item_name': 'Loadout', 'playtime_forever': 140, 'playtime_2weeks': 0}, {'item_id': '212500', 'item_name': 'The Lord of the Rings Online™', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '218230', 'item_name': 'PlanetSide 2', 'playtime_forever': 2808, 'playtime_2weeks': 0}, {'item_id': '230410', 'item_name': 'Warframe', 'playtime_forever': 252, 'playtime_2weeks': 0}, {'item_id': '236390', 'item_name': 'War Thunder', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '238960', 'item_name': 'Path of Exile', 'playtime_forever': 3579, 'playtime_2weeks': 0}, {'item_id': '243870', 'item_name': \"Tom Clancy's Ghost Recon Phantoms - NA\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '263500', 'item_name': 'Dragons and Titans', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '39120', 'item_name': 'RIFT', 'playtime_forever': 2866, 'playtime_2weeks': 0}, {'item_id': '242720', 'item_name': 'GunZ 2: The Second Duel', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '250420', 'item_name': '8BitMMO', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '262410', 'item_name': 'World of Guns: Gun Disassembly', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '265630', 'item_name': 'Fistful of Frags', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '272060', 'item_name': 'Serena', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '202090', 'item_name': 'Magicka: Wizard Wars', 'playtime_forever': 12, 'playtime_2weeks': 0}, {'item_id': '224260', 'item_name': 'No More Room in Hell', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '226320', 'item_name': 'Marvel Heroes 2016', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '239220', 'item_name': 'The Mighty Quest For Epic Loot', 'playtime_forever': 223, 'playtime_2weeks': 0}, {'item_id': '241640', 'item_name': 'Haunted Memories', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '245550', 'item_name': 'Free to Play', 'playtime_forever': 80, 'playtime_2weeks': 0}, {'item_id': '343450', 'item_name': 'Free To Play (Streaming)', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '231200', 'item_name': 'Kentucky Route Zero', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '224580', 'item_name': 'Arma 2: DayZ Mod', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '221040', 'item_name': 'Resident Evil 6 / Biohazard 6', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '6000', 'item_name': 'STAR WARS™ Republic Commando', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '6020', 'item_name': 'STAR WARS™ Jedi Knight: Jedi Academy™', 'playtime_forever': 4, 'playtime_2weeks': 0}, {'item_id': '6030', 'item_name': 'STAR WARS™ Jedi Knight II: Jedi Outcast™', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '6060', 'item_name': 'STAR WARS™ Battlefront™ II', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32350', 'item_name': 'STAR WARS™ Starfighter™', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32370', 'item_name': 'STAR WARS™: Knights of the Old Republic™', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32380', 'item_name': 'STAR WARS™ Jedi Knight: Dark Forces II', 'playtime_forever': 3, 'playtime_2weeks': 0}, {'item_id': '32390', 'item_name': 'STAR WARS™ Jedi Knight: Mysteries of the Sith™', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32400', 'item_name': 'STAR WARS™: Dark Forces', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32420', 'item_name': 'STAR WARS™: The Clone Wars - Republic Heroes™', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32430', 'item_name': 'STAR WARS™: The Force Unleashed™ Ultimate Sith Edition', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32470', 'item_name': 'STAR WARS™ Empire at War: Gold Pack', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '32500', 'item_name': 'STAR WARS™: The Force Unleashed™ II', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '208580', 'item_name': 'STAR WARS™ Knights of the Old Republic™ II: The Sith Lords™', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '225260', 'item_name': 'Brütal Legend', 'playtime_forever': 41, 'playtime_2weeks': 0}, {'item_id': '233450', 'item_name': 'Prison Architect', 'playtime_forever': 99, 'playtime_2weeks': 0}, {'item_id': '8870', 'item_name': 'BioShock Infinite', 'playtime_forever': 365, 'playtime_2weeks': 0}, {'item_id': '224600', 'item_name': 'Defiance', 'playtime_forever': 6899, 'playtime_2weeks': 0}, {'item_id': '216250', 'item_name': 'Dead Island Riptide', 'playtime_forever': 1342, 'playtime_2weeks': 0}, {'item_id': '222480', 'item_name': 'Resident Evil Revelations / Biohazard Revelations', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '228300', 'item_name': 'Remember Me', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '35720', 'item_name': 'Trine 2', 'playtime_forever': 53, 'playtime_2weeks': 0}, {'item_id': '242760', 'item_name': 'The Forest', 'playtime_forever': 1677, 'playtime_2weeks': 0}, {'item_id': '206420', 'item_name': 'Saints Row IV', 'playtime_forever': 2402, 'playtime_2weeks': 0}, {'item_id': '213850', 'item_name': 'Magic 2014 ', 'playtime_forever': 861, 'playtime_2weeks': 0}, {'item_id': '244810', 'item_name': 'Foul Play', 'playtime_forever': 19, 'playtime_2weeks': 0}, {'item_id': '244850', 'item_name': 'Space Engineers', 'playtime_forever': 60, 'playtime_2weeks': 0}, {'item_id': '6880', 'item_name': 'Just Cause', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '8190', 'item_name': 'Just Cause 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '239030', 'item_name': 'Papers, Please', 'playtime_forever': 98, 'playtime_2weeks': 0}, {'item_id': '218620', 'item_name': 'PAYDAY 2', 'playtime_forever': 2741, 'playtime_2weeks': 0}, {'item_id': '209000', 'item_name': 'Batman™: Arkham Origins', 'playtime_forever': 2369, 'playtime_2weeks': 0}, {'item_id': '239820', 'item_name': 'Game Dev Tycoon', 'playtime_forever': 448, 'playtime_2weeks': 0}, {'item_id': '250320', 'item_name': 'The Wolf Among Us', 'playtime_forever': 668, 'playtime_2weeks': 0}, {'item_id': '219640', 'item_name': 'Chivalry: Medieval Warfare', 'playtime_forever': 34, 'playtime_2weeks': 0}, {'item_id': '232210', 'item_name': 'Patch testing for Chivalry', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '208610', 'item_name': 'Skullgirls ∞Endless Beta∞', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '245170', 'item_name': 'Skullgirls', 'playtime_forever': 212, 'playtime_2weeks': 0}, {'item_id': '228560', 'item_name': 'Teenage Mutant Ninja Turtles: Out of the Shadows', 'playtime_forever': 1237, 'playtime_2weeks': 0}, {'item_id': '251570', 'item_name': '7 Days to Die', 'playtime_forever': 3034, 'playtime_2weeks': 0}, {'item_id': '252350', 'item_name': 'Double Dragon Neon', 'playtime_forever': 264, 'playtime_2weeks': 0}, {'item_id': '252490', 'item_name': 'Rust', 'playtime_forever': 3483, 'playtime_2weeks': 0}, {'item_id': '252950', 'item_name': 'Rocket League', 'playtime_forever': 915, 'playtime_2weeks': 0}, {'item_id': '241540', 'item_name': 'State of Decay', 'playtime_forever': 2099, 'playtime_2weeks': 0}, {'item_id': '237890', 'item_name': 'Agarest: Generations of War', 'playtime_forever': 135, 'playtime_2weeks': 0}, {'item_id': '242050', 'item_name': \"Assassin's Creed IV Black Flag\", 'playtime_forever': 6221, 'playtime_2weeks': 0}, {'item_id': '234530', 'item_name': 'War of the Vikings', 'playtime_forever': 2509, 'playtime_2weeks': 0}, {'item_id': '257350', 'item_name': \"Baldur's Gate II: Enhanced Edition\", 'playtime_forever': 1, 'playtime_2weeks': 0}, {'item_id': '243470', 'item_name': 'Watch_Dogs', 'playtime_forever': 2043, 'playtime_2weeks': 0}, {'item_id': '247730', 'item_name': 'Nether', 'playtime_forever': 3114, 'playtime_2weeks': 0}, {'item_id': '260730', 'item_name': 'Desperados - Wanted Dead or Alive', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '261030', 'item_name': 'The Walking Dead: Season Two', 'playtime_forever': 637, 'playtime_2weeks': 0}, {'item_id': '242700', 'item_name': 'Injustice: Gods Among Us Ultimate Edition', 'playtime_forever': 368, 'playtime_2weeks': 0}, {'item_id': '262060', 'item_name': 'Darkest Dungeon', 'playtime_forever': 332, 'playtime_2weeks': 0}, {'item_id': '263440', 'item_name': 'The Stomping Land', 'playtime_forever': 142, 'playtime_2weeks': 0}, {'item_id': '108600', 'item_name': 'Project Zomboid', 'playtime_forever': 160, 'playtime_2weeks': 0}, {'item_id': '211820', 'item_name': 'Starbound', 'playtime_forever': 137, 'playtime_2weeks': 0}, {'item_id': '367540', 'item_name': 'Starbound - Unstable', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '41900', 'item_name': \"The Bard's Tale\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '240760', 'item_name': 'Wasteland 2', 'playtime_forever': 710, 'playtime_2weeks': 0}, {'item_id': '259130', 'item_name': 'Wasteland 1 - The Original Classic', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '404730', 'item_name': \"Wasteland 2: Director's Cut\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '221100', 'item_name': 'DayZ', 'playtime_forever': 131, 'playtime_2weeks': 0}, {'item_id': '202170', 'item_name': 'Sleeping Dogs™', 'playtime_forever': 1322, 'playtime_2weeks': 0}, {'item_id': '268870', 'item_name': 'Satellite Reign', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '239840', 'item_name': 'Dead State', 'playtime_forever': 718, 'playtime_2weeks': 0}, {'item_id': '271590', 'item_name': 'Grand Theft Auto V', 'playtime_forever': 6740, 'playtime_2weeks': 0}, {'item_id': '273110', 'item_name': 'Counter-Strike Nexon: Zombies', 'playtime_forever': 6, 'playtime_2weeks': 0}, {'item_id': '274310', 'item_name': 'Always Sometimes Monsters', 'playtime_forever': 501, 'playtime_2weeks': 0}, {'item_id': '213670', 'item_name': 'South Park™: The Stick of Truth™', 'playtime_forever': 1105, 'playtime_2weeks': 0}, {'item_id': '278080', 'item_name': 'DYNASTY WARRIORS 8: Xtreme Legends Complete Edition', 'playtime_forever': 671, 'playtime_2weeks': 0}, {'item_id': '48700', 'item_name': 'Mount & Blade: Warband', 'playtime_forever': 871, 'playtime_2weeks': 0}, {'item_id': '254700', 'item_name': 'resident evil 4 / biohazard 4', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '235210', 'item_name': 'Strider', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '290140', 'item_name': 'Echo of Soul', 'playtime_forever': 44, 'playtime_2weeks': 0}, {'item_id': '290300', 'item_name': 'Rebel Galaxy', 'playtime_forever': 96, 'playtime_2weeks': 0}, {'item_id': '293780', 'item_name': 'Crawl', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '295110', 'item_name': 'H1Z1: Just Survive', 'playtime_forever': 4778, 'playtime_2weeks': 0}, {'item_id': '362300', 'item_name': 'H1Z1: Just Survive Test Server', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '433850', 'item_name': 'H1Z1: King of the Kill', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '439700', 'item_name': 'H1Z1: King of the Kill Test Server', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '222900', 'item_name': 'Dead Island: Epidemic', 'playtime_forever': 268, 'playtime_2weeks': 0}, {'item_id': '300550', 'item_name': \"Shadowrun: Dragonfall - Director's Cut\", 'playtime_forever': 1056, 'playtime_2weeks': 0}, {'item_id': '300570', 'item_name': 'Infinifactory', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '300580', 'item_name': 'GALAK-Z', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '301520', 'item_name': 'Robocraft', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '302270', 'item_name': 'Dungeon Defenders Eternity', 'playtime_forever': 551, 'playtime_2weeks': 0}, {'item_id': '304050', 'item_name': 'Trove', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '304030', 'item_name': 'ArcheAge', 'playtime_forever': 12249, 'playtime_2weeks': 0}, {'item_id': '304930', 'item_name': 'Unturned', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '244630', 'item_name': 'NEOTOKYO°', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '312990', 'item_name': 'The Expendabros', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '227940', 'item_name': 'Heroes & Generals', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '265590', 'item_name': 'The Red Solstice', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '241930', 'item_name': 'Middle-earth: Shadow of Mordor', 'playtime_forever': 1494, 'playtime_2weeks': 0}, {'item_id': '265550', 'item_name': 'Dead Rising 3', 'playtime_forever': 171, 'playtime_2weeks': 0}, {'item_id': '226720', 'item_name': 'Lost Planet 3', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '323370', 'item_name': 'TERA', 'playtime_forever': 1785, 'playtime_2weeks': 0}, {'item_id': '327510', 'item_name': 'WASTED', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '261640', 'item_name': 'Borderlands: The Pre-Sequel', 'playtime_forever': 2462, 'playtime_2weeks': 0}, {'item_id': '330840', 'item_name': 'Game of Thrones - A Telltale Games Series', 'playtime_forever': 719, 'playtime_2weeks': 0}, {'item_id': '17570', 'item_name': 'Pirates, Vikings, & Knights II', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '305620', 'item_name': 'The Long Dark', 'playtime_forever': 404, 'playtime_2weeks': 0}, {'item_id': '323470', 'item_name': 'DRAGON BALL XENOVERSE', 'playtime_forever': 920, 'playtime_2weeks': 0}, {'item_id': '333930', 'item_name': 'Dirty Bomb', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '249050', 'item_name': 'Dungeon of the Endless', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '236110', 'item_name': 'Dungeon Defenders II', 'playtime_forever': 88, 'playtime_2weeks': 0}, {'item_id': '337850', 'item_name': 'Avernum 2: Crystal Souls', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '339120', 'item_name': \"Fork Parker's Holiday Profit Hike\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '342200', 'item_name': 'MechWarrior Online', 'playtime_forever': 699, 'playtime_2weeks': 0}, {'item_id': '314660', 'item_name': \"Oddworld: New 'n' Tasty\", 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '345520', 'item_name': 'Infinite Crisis™', 'playtime_forever': 406, 'playtime_2weeks': 0}, {'item_id': '346110', 'item_name': 'ARK: Survival Evolved', 'playtime_forever': 23434, 'playtime_2weeks': 0}, {'item_id': '407530', 'item_name': 'ARK: Survival Of The Fittest', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '347160', 'item_name': 'Steredenn', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '287290', 'item_name': 'Resident Evil Revelations 2 / Biohazard Revelations 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '339280', 'item_name': 'Strife', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '351570', 'item_name': 'Killing Floor: Uncovered', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '232090', 'item_name': 'Killing Floor 2', 'playtime_forever': 1171, 'playtime_2weeks': 0}, {'item_id': '232150', 'item_name': 'Killing Floor 2 - SDK', 'playtime_forever': 2, 'playtime_2weeks': 0}, {'item_id': '362070', 'item_name': 'Metal Reaper Online', 'playtime_forever': 8, 'playtime_2weeks': 0}, {'item_id': '47780', 'item_name': 'Dead Space 2', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '362680', 'item_name': 'Fran Bow', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '329460', 'item_name': 'JumpJet Rex', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '365590', 'item_name': \"Tom Clancy's The Division\", 'playtime_forever': 10442, 'playtime_2weeks': 0}, {'item_id': '329050', 'item_name': 'Devil May Cry® 4 Special Edition', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '370360', 'item_name': 'TIS-100', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '292030', 'item_name': 'The Witcher 3: Wild Hunt', 'playtime_forever': 2140, 'playtime_2weeks': 0}, {'item_id': '373480', 'item_name': '1993 Space Machine', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '377160', 'item_name': 'Fallout 4', 'playtime_forever': 7194, 'playtime_2weeks': 0}, {'item_id': '386070', 'item_name': 'Planetary Annihilation: TITANS', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '386360', 'item_name': 'SMITE', 'playtime_forever': 498, 'playtime_2weeks': 0}, {'item_id': '234140', 'item_name': 'Mad Max', 'playtime_forever': 1123, 'playtime_2weeks': 0}, {'item_id': '393420', 'item_name': 'Hurtworld', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '445900', 'item_name': 'Hurtworld SDK', 'playtime_forever': 0, 'playtime_2weeks': 0}, {'item_id': '394310', 'item_name': 'Punch Club', 'playtime_forever': 416, 'playtime_2weeks': 0}, {'item_id': '413150', 'item_name': 'Stardew Valley', 'playtime_forever': 1321, 'playtime_2weeks': 0}, {'item_id': '268500', 'item_name': 'XCOM 2', 'playtime_forever': 620, 'playtime_2weeks': 0}, {'item_id': '444560', 'item_name': 'Agent Origins: Escape', 'playtime_forever': 9, 'playtime_2weeks': 0}, {'item_id': '275850', 'item_name': \"No Man's Sky\", 'playtime_forever': 564, 'playtime_2weeks': 0}]}\n"]}]},{"cell_type":"code","source":["# prompt: Load data using json from /content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Processing Data/user_tags_and_specs_data.json.gz\n","\n","import gzip\n","import json\n","\n","file_path = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Processing Data/user_tags_and_specs_data.json.gz\"\n","\n","try:\n"," with gzip.open(file_path, 'rt', encoding='utf-8') as gzip_file:\n"," data_bundle_interactions = json.load(gzip_file)\n"," # Now you can work with the loaded JSON data\n"," print(f\"Successfully loaded {len(data_bundle_interactions)} items from the JSON file.\")\n","\n","except FileNotFoundError:\n"," print(f\"Error: File not found at {file_path}\")\n","except json.JSONDecodeError as e:\n"," print(f\"Error decoding JSON: {e}\")\n","except Exception as e:\n"," print(f\"An unexpected error occurred: {e}\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"QyPVHFFbSpOe","executionInfo":{"status":"ok","timestamp":1736565158539,"user_tz":-420,"elapsed":20192,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"cb363d92-ff3e-4524-f3b3-66feee09e7fc"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Successfully loaded 9675 items from the JSON file.\n"]}]},{"cell_type":"code","source":["input_default_tags = {}\n","input_default_specs = {}\n","\n","for user_id, recommendations in data_bundle_interactions.items():\n"," for bundle_id, recommendation in recommendations.items():\n"," for keys in recommendation['frequent_distinct_tags'].items():\n"," if keys[0] not in input_default_tags:\n"," input_default_tags[keys[0]] = 0\n","\n"," for keys in recommendation['frequent_distinct_specs'].items():\n"," if keys[0] not in input_default_specs:\n"," input_default_specs[keys[0]] = 0\n"," break\n"," break"],"metadata":{"id":"amTibdP9S850"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["bundle_tags = {}\n","bundle_specs = {}\n","for bundle_id, bundle_info in bundle_data.items():\n"," bundle_tags[bundle_id] = {}\n"," bundle_specs[bundle_id] = {}\n"," for item_id in bundle_info[\"items\"]:\n"," if item_id in items_dictionary:\n"," if 'tags' in items_dictionary[item_id]:\n"," for tag in items_dictionary[item_id]['tags']:\n"," if tag in input_default_tags:\n"," if tag not in bundle_tags[bundle_id]:\n"," bundle_tags[bundle_id][tag] = 1\n"," else:\n"," bundle_tags[bundle_id][tag] += 1\n"," if 'specs' in items_dictionary[item_id]:\n"," for spec in items_dictionary[item_id]['specs']:\n"," if spec in input_default_specs:\n"," if spec not in bundle_specs[bundle_id]:\n"," bundle_specs[bundle_id][spec] = 1\n"," else:\n"," bundle_specs[bundle_id][spec] += 1"],"metadata":{"id":"Fhghu_CXXEM8"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["bundle_specs['494']"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"uLJD8145apO-","executionInfo":{"status":"ok","timestamp":1736398562735,"user_tz":-420,"elapsed":508,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"0aec2697-45e1-4c40-ec38-ac06f081800f"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["{'Single-player': 2,\n"," 'Steam Achievements': 2,\n"," 'Steam Trading Cards': 2,\n"," 'Steam Workshop': 2,\n"," 'Steam Cloud': 2,\n"," 'Stats': 2,\n"," 'Steam Leaderboards': 2,\n"," 'Includes level editor': 1}"]},"metadata":{},"execution_count":24}]},{"cell_type":"code","source":["path_list_of_bundles = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Processing Data/Previous\""],"metadata":{"id":"Atn1W6diVxRm"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["i = 0\n","data_bundle_temp_to_save = []\n","for tag in input_default_tags:\n"," data_bundle_temp_to_save = []\n"," for bundle_id in bundle_tags:\n"," if tag in bundle_tags[bundle_id]:\n"," data_bundle_temp_to_save.append(bundle_id)\n","\n"," np.save(f\"{path_list_of_bundles}/Tags/bundle_for_tag_{tag}.npy\", np.array(data_bundle_temp_to_save))\n","\n"," print(f\"{i} / {len(input_default_tags)}\")\n"," i += 1"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"qNZySb2ua8AA","executionInfo":{"status":"ok","timestamp":1736399179541,"user_tz":-420,"elapsed":2799,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"49c6916e-9d24-44d2-cebf-96f38f90d5b8"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["0 / 204\n","1 / 204\n","2 / 204\n","3 / 204\n","4 / 204\n","5 / 204\n","6 / 204\n","7 / 204\n","8 / 204\n","9 / 204\n","10 / 204\n","11 / 204\n","12 / 204\n","13 / 204\n","14 / 204\n","15 / 204\n","16 / 204\n","17 / 204\n","18 / 204\n","19 / 204\n","20 / 204\n","21 / 204\n","22 / 204\n","23 / 204\n","24 / 204\n","25 / 204\n","26 / 204\n","27 / 204\n","28 / 204\n","29 / 204\n","30 / 204\n","31 / 204\n","32 / 204\n","33 / 204\n","34 / 204\n","35 / 204\n","36 / 204\n","37 / 204\n","38 / 204\n","39 / 204\n","40 / 204\n","41 / 204\n","42 / 204\n","43 / 204\n","44 / 204\n","45 / 204\n","46 / 204\n","47 / 204\n","48 / 204\n","49 / 204\n","50 / 204\n","51 / 204\n","52 / 204\n","53 / 204\n","54 / 204\n","55 / 204\n","56 / 204\n","57 / 204\n","58 / 204\n","59 / 204\n","60 / 204\n","61 / 204\n","62 / 204\n","63 / 204\n","64 / 204\n","65 / 204\n","66 / 204\n","67 / 204\n","68 / 204\n","69 / 204\n","70 / 204\n","71 / 204\n","72 / 204\n","73 / 204\n","74 / 204\n","75 / 204\n","76 / 204\n","77 / 204\n","78 / 204\n","79 / 204\n","80 / 204\n","81 / 204\n","82 / 204\n","83 / 204\n","84 / 204\n","85 / 204\n","86 / 204\n","87 / 204\n","88 / 204\n","89 / 204\n","90 / 204\n","91 / 204\n","92 / 204\n","93 / 204\n","94 / 204\n","95 / 204\n","96 / 204\n","97 / 204\n","98 / 204\n","99 / 204\n","100 / 204\n","101 / 204\n","102 / 204\n","103 / 204\n","104 / 204\n","105 / 204\n","106 / 204\n","107 / 204\n","108 / 204\n","109 / 204\n","110 / 204\n","111 / 204\n","112 / 204\n","113 / 204\n","114 / 204\n","115 / 204\n","116 / 204\n","117 / 204\n","118 / 204\n","119 / 204\n","120 / 204\n","121 / 204\n","122 / 204\n","123 / 204\n","124 / 204\n","125 / 204\n","126 / 204\n","127 / 204\n","128 / 204\n","129 / 204\n","130 / 204\n","131 / 204\n","132 / 204\n","133 / 204\n","134 / 204\n","135 / 204\n","136 / 204\n","137 / 204\n","138 / 204\n","139 / 204\n","140 / 204\n","141 / 204\n","142 / 204\n","143 / 204\n","144 / 204\n","145 / 204\n","146 / 204\n","147 / 204\n","148 / 204\n","149 / 204\n","150 / 204\n","151 / 204\n","152 / 204\n","153 / 204\n","154 / 204\n","155 / 204\n","156 / 204\n","157 / 204\n","158 / 204\n","159 / 204\n","160 / 204\n","161 / 204\n","162 / 204\n","163 / 204\n","164 / 204\n","165 / 204\n","166 / 204\n","167 / 204\n","168 / 204\n","169 / 204\n","170 / 204\n","171 / 204\n","172 / 204\n","173 / 204\n","174 / 204\n","175 / 204\n","176 / 204\n","177 / 204\n","178 / 204\n","179 / 204\n","180 / 204\n","181 / 204\n","182 / 204\n","183 / 204\n","184 / 204\n","185 / 204\n","186 / 204\n","187 / 204\n","188 / 204\n","189 / 204\n","190 / 204\n","191 / 204\n","192 / 204\n","193 / 204\n","194 / 204\n","195 / 204\n","196 / 204\n","197 / 204\n","198 / 204\n","199 / 204\n","200 / 204\n","201 / 204\n","202 / 204\n","203 / 204\n"]}]},{"cell_type":"code","source":["data_bundle_temp_to_save"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ATV_9973dVoE","executionInfo":{"status":"ok","timestamp":1736399217372,"user_tz":-420,"elapsed":529,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"f207c5c2-68f2-4409-a9a2-655c87d53469"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["['1274', '920', '425', '770', '772', '776', '767', '285', '435']"]},"metadata":{},"execution_count":27}]},{"cell_type":"code","source":["i = 0\n","for spec in input_default_specs:\n"," data_bundle_temp_to_save = []\n"," for bundle_id in bundle_specs:\n"," if spec in bundle_specs[bundle_id]:\n"," data_bundle_temp_to_save.append(bundle_id)\n","\n"," np.save(f\"{path_list_of_bundles}/Specs/bundle_for_spec_{spec.replace('/', '')}.npy\", np.array(data_bundle_temp_to_save))\n","\n"," print(f\"{i} / {len(input_default_specs)}\")\n"," i += 1"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"OO8q4lfiddZA","executionInfo":{"status":"ok","timestamp":1736399604221,"user_tz":-420,"elapsed":467,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"46bfff98-0f3d-40f0-e97e-c750cb521261"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["0 / 21\n","1 / 21\n","2 / 21\n","3 / 21\n","4 / 21\n","5 / 21\n","6 / 21\n","7 / 21\n","8 / 21\n","9 / 21\n","10 / 21\n","11 / 21\n","12 / 21\n","13 / 21\n","14 / 21\n","15 / 21\n","16 / 21\n","17 / 21\n","18 / 21\n","19 / 21\n","20 / 21\n"]}]},{"cell_type":"markdown","source":["### Generate Matrix Data"],"metadata":{"id":"PRLv0p8UhlQD"}},{"cell_type":"code","source":["items_dictionary['32150']"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"NbyzDA5Sj-of","executionInfo":{"status":"ok","timestamp":1736400968680,"user_tz":-420,"elapsed":460,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"8583477d-0326-4883-872f-ecbbd26fe507"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["{'publisher': 'TrueThought',\n"," 'genres': ['Casual', 'Indie', 'Strategy'],\n"," 'app_name': 'Everyday Genius: SquareLogic',\n"," 'sentiment': 'Very Positive',\n"," 'title': 'Everyday Genius: SquareLogic',\n"," 'url': 'http://store.steampowered.com/app/32150/Everyday_Genius_SquareLogic/',\n"," 'release_date': '2009-10-09',\n"," 'tags': ['Casual', 'Puzzle', 'Indie', 'Strategy', 'Relaxing'],\n"," 'reviews_url': 'http://steamcommunity.com/app/32150/reviews/?browsefilter=mostrecent&p=1',\n"," 'specs': ['Single-player',\n"," 'Steam Achievements',\n"," 'Steam Cloud',\n"," 'Stats',\n"," 'Steam Leaderboards'],\n"," 'price': 4.99,\n"," 'early_access': False,\n"," 'id': '32150',\n"," 'developer': 'TrueThought'}"]},"metadata":{},"execution_count":33}]},{"cell_type":"code","source":["# prompt: Load data from /content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/bundle_data.json.gz using json\n","\n","import json\n","import gzip\n","import ast\n","\n","# Open the gzipped file\n","data_dict = None\n","\n","file_path = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/australian_user_reviews.json.gz\"\n","file_path_write = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/australian_user_reviews_process.json.gz\"\n","\n","with gzip.open(f\"{file_path}\", 'rt', encoding='utf-8') as f, gzip.open(file_path_write, 'wt', encoding='utf-8') as outfile:\n"," for i, line in enumerate(f):\n"," # Remove the trailing newline character\n"," cleaned_string = line.strip()\n"," try:\n"," data_dict = ast.literal_eval(cleaned_string)\n"," for review in data_dict[\"reviews\"]:\n"," json.dump({ \"user_id\": data_dict['user_id'], \"item_id\": review['item_id'], \"rating\": review['helpful'] }, outfile, ensure_ascii=False)\n"," outfile.write('\\n')\n"," except (ValueError, SyntaxError) as e:\n"," print(f\"Failed to convert string to dictionary: {e}\")\n"," if i % 1000 == 0:\n"," print(f\"{i} / 7,793,069\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"jtfmN1NFhrHx","executionInfo":{"status":"ok","timestamp":1736405137171,"user_tz":-420,"elapsed":6753,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"0c7dc159-e35a-49a4-b317-dee040d6fdc6"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["0 / 7,793,069\n","1000 / 7,793,069\n","2000 / 7,793,069\n","3000 / 7,793,069\n","4000 / 7,793,069\n","5000 / 7,793,069\n","6000 / 7,793,069\n","7000 / 7,793,069\n","8000 / 7,793,069\n","9000 / 7,793,069\n","10000 / 7,793,069\n","11000 / 7,793,069\n","12000 / 7,793,069\n","13000 / 7,793,069\n","14000 / 7,793,069\n","15000 / 7,793,069\n","16000 / 7,793,069\n","17000 / 7,793,069\n","18000 / 7,793,069\n","19000 / 7,793,069\n","20000 / 7,793,069\n","21000 / 7,793,069\n","22000 / 7,793,069\n","23000 / 7,793,069\n","24000 / 7,793,069\n","25000 / 7,793,069\n"]}]},{"cell_type":"code","source":["# prompt: Get the percent value from string on unique_ratings\n","\n","import re\n","\n","def extract_percent(rating_str):\n"," \"\"\"\n"," Extracts the numeric percentage value from a string.\n","\n"," Args:\n"," rating_str: The input string potentially containing a percentage value.\n","\n"," Returns:\n"," The numeric percentage value as a float, or None if no percentage is found.\n"," \"\"\"\n"," match = re.search(r\"(\\d+(\\.\\d+)?)%\", rating_str) # Match digits (optional decimal) followed by %\n"," if match:\n"," return float(match.group(1))\n"," return None"],"metadata":{"id":"OSY78hII5nst"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["file_path_write = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Datasets/australian_user_reviews_process.json.gz\"\n","data_reviews = []\n","with gzip.open(f\"{file_path_write}\", 'rt', encoding='utf-8') as f:\n"," for i, line in enumerate(f):\n"," # Remove the trailing newline character\n"," cleaned_string = line.strip()\n"," try:\n"," data_dict = ast.literal_eval(cleaned_string)\n"," percent = extract_percent(str(data_dict[\"rating\"])) # Convert to string before processing\n"," if percent is None:\n"," percent = 0.0\n"," data_dict[\"rating\"] = percent\n"," data_reviews.append(data_dict)\n"," except (ValueError, SyntaxError) as e:\n"," print(f\"Failed to convert string to dictionary: {e}\")"],"metadata":{"id":"eOGfmEhPstp1"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["len(data_reviews)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"CGMVGRCU4pTo","executionInfo":{"status":"ok","timestamp":1736406941390,"user_tz":-420,"elapsed":482,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"61a99789-6d71-4094-d191-1a9a01e1ab25"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["59305"]},"metadata":{},"execution_count":50}]},{"cell_type":"code","source":["# prompt: get unique rating from data_reviews\n","\n","unique_ratings = set()\n","for review in data_reviews:\n"," unique_ratings.add(review['rating'])\n","unique_ratings"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"collapsed":true,"id":"1zSqCNkn40KY","executionInfo":{"status":"ok","timestamp":1736565181318,"user_tz":-420,"elapsed":297,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"ebf6a3b4-2804-47c5-d8d5-f55a16fbe6c1"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["{0.0,\n"," 2.0,\n"," 3.0,\n"," 4.0,\n"," 5.0,\n"," 6.0,\n"," 7.0,\n"," 8.0,\n"," 9.0,\n"," 10.0,\n"," 11.0,\n"," 12.0,\n"," 13.0,\n"," 14.0,\n"," 15.0,\n"," 16.0,\n"," 17.0,\n"," 18.0,\n"," 19.0,\n"," 20.0,\n"," 21.0,\n"," 22.0,\n"," 23.0,\n"," 24.0,\n"," 25.0,\n"," 26.0,\n"," 27.0,\n"," 28.0,\n"," 29.0,\n"," 30.0,\n"," 31.0,\n"," 32.0,\n"," 33.0,\n"," 34.0,\n"," 35.0,\n"," 36.0,\n"," 37.0,\n"," 38.0,\n"," 39.0,\n"," 40.0,\n"," 41.0,\n"," 42.0,\n"," 43.0,\n"," 44.0,\n"," 45.0,\n"," 46.0,\n"," 47.0,\n"," 48.0,\n"," 49.0,\n"," 50.0,\n"," 51.0,\n"," 52.0,\n"," 53.0,\n"," 54.0,\n"," 55.0,\n"," 56.0,\n"," 57.0,\n"," 58.0,\n"," 59.0,\n"," 60.0,\n"," 61.0,\n"," 62.0,\n"," 63.0,\n"," 64.0,\n"," 65.0,\n"," 66.0,\n"," 67.0,\n"," 68.0,\n"," 69.0,\n"," 70.0,\n"," 71.0,\n"," 72.0,\n"," 73.0,\n"," 74.0,\n"," 75.0,\n"," 76.0,\n"," 77.0,\n"," 78.0,\n"," 79.0,\n"," 80.0,\n"," 81.0,\n"," 82.0,\n"," 83.0,\n"," 84.0,\n"," 85.0,\n"," 86.0,\n"," 87.0,\n"," 88.0,\n"," 89.0,\n"," 90.0,\n"," 91.0,\n"," 92.0,\n"," 93.0,\n"," 94.0,\n"," 95.0,\n"," 96.0,\n"," 97.0,\n"," 98.0,\n"," 100.0}"]},"metadata":{},"execution_count":8}]},{"cell_type":"code","source":["# prompt: data_reviews convert to dictionary with structure user_id -> item_id\n","\n","user_item_dict = {}\n","for review in data_reviews:\n"," user_id = review['user_id']\n"," item_id = review['item_id']\n"," if user_id not in user_item_dict:\n"," user_item_dict[user_id] = {}\n"," user_item_dict[user_id][item_id] = review['rating']"],"metadata":{"id":"2uDNR7dl7HH1"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["user_bundle_histories = []\n","\n","for user_id, recommendations in data_bundle_interactions.items():\n"," for bundle_id, recommendation in recommendations.items():\n"," rating = []\n"," if user_id in user_item_dict:\n"," if bundle_id in bundle_data:\n"," for item_id in bundle_data[bundle_id][\"items\"]:\n"," if item_id in user_item_dict[user_id]:\n"," rating.append(user_item_dict[user_id][item_id])\n"," if len(rating) > 0:\n"," rating = sum(rating) / len(rating)\n"," else:\n"," rating = 0.0\n"," user_bundle_histories.append({ \"user_id\": user_id, \"bundle_id\": bundle_id, \"label\": recommendation[\"label\"], \"rating\": rating / 20 })"],"metadata":{"id":"HjtZTpXh65jv"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# prompt: Check how many data that has rating more than 0.0 in user_bundle_histories\n","\n","count = 0\n","for entry in user_bundle_histories:\n"," if entry[\"rating\"] > 0.0:\n"," count += 1\n","print(f\"Number of data entries with rating > 0.0: {count}\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"krXSWUIP612O","executionInfo":{"status":"ok","timestamp":1736565204797,"user_tz":-420,"elapsed":324,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"27701e0e-4d61-492c-d570-b0f53bb4e1c1"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Number of data entries with rating > 0.0: 1870\n"]}]},{"cell_type":"code","source":["len(user_bundle_histories)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Dm2308ezVjdk","executionInfo":{"status":"ok","timestamp":1736565207436,"user_tz":-420,"elapsed":317,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"dbc74f18-a603-4f8a-bccd-814c179af1ad"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["103453"]},"metadata":{},"execution_count":12}]},{"cell_type":"markdown","source":["### Create matrix factorization all"],"metadata":{"id":"4b8hrqoiLQ2z"}},{"cell_type":"code","source":["!pip install surprise"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"e-NW0-DW9QSS","executionInfo":{"status":"ok","timestamp":1736565315279,"user_tz":-420,"elapsed":80368,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"fb840572-1cfa-4cec-d3bb-46592127cbbe"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Collecting surprise\n"," Downloading surprise-0.1-py2.py3-none-any.whl.metadata (327 bytes)\n","Collecting scikit-surprise (from surprise)\n"," Downloading scikit_surprise-1.1.4.tar.gz (154 kB)\n","\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m154.4/154.4 kB\u001b[0m \u001b[31m3.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n"," Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n"," Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n","Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from scikit-surprise->surprise) (1.4.2)\n","Requirement already satisfied: numpy>=1.19.5 in /usr/local/lib/python3.10/dist-packages (from scikit-surprise->surprise) (1.26.4)\n","Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from scikit-surprise->surprise) (1.13.1)\n","Downloading surprise-0.1-py2.py3-none-any.whl (1.8 kB)\n","Building wheels for collected packages: scikit-surprise\n"," Building wheel for scikit-surprise (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n"," Created wheel for scikit-surprise: filename=scikit_surprise-1.1.4-cp310-cp310-linux_x86_64.whl size=2357277 sha256=482fb4f9133c86478d975acb90e0db0203516ed3f193f2123ac5532455888650\n"," Stored in directory: /root/.cache/pip/wheels/4b/3f/df/6acbf0a40397d9bf3ff97f582cc22fb9ce66adde75bc71fd54\n","Successfully built scikit-surprise\n","Installing collected packages: scikit-surprise, surprise\n","Successfully installed scikit-surprise-1.1.4 surprise-0.1\n"]}]},{"cell_type":"code","source":["# prompt: From this data user_bundle_histories, apply SVD and SVD++ with Hyperparameter tuning and Gridsearch and Cross validation 5\n","\n","import pandas as pd\n","from surprise import SVD, SVDpp\n","from surprise import Dataset, Reader\n","from surprise.model_selection import GridSearchCV, cross_validate\n","\n","# Create a pandas DataFrame from user_bundle_histories\n","df = pd.DataFrame(user_bundle_histories)\n","\n","# Define the rating scale for the Surprise library\n","reader = Reader(rating_scale=(0, 5))\n","\n","# Load the data into Surprise Dataset format\n","data = Dataset.load_from_df(df[['user_id', 'bundle_id', 'rating']], reader)\n","\n","# Define parameter grids for SVD and SVD++\n","param_grid_svd = {'n_factors': [50, 100, 150], 'n_epochs': [20, 30], 'lr_all': [0.005, 0.01], 'reg_all': [0.02, 0.1]}\n","param_grid_svdpp = {'n_factors': [20, 50], 'n_epochs': [20, 30], 'lr_all': [0.005, 0.01], 'reg_all': [0.02, 0.1]}\n","\n","# Perform hyperparameter tuning with GridSearchCV for SVD\n","gs_svd = GridSearchCV(SVD, param_grid_svd, measures=['rmse', 'mae'], cv=5)\n","gs_svd.fit(data)\n","\n","# Print the best hyperparameters and RMSE for SVD\n","print(\"SVD Best RMSE:\", gs_svd.best_score['rmse'])\n","print(\"SVD Best MAE:\", gs_svd.best_score['mae'])\n","print(\"SVD Best Params:\", gs_svd.best_params['rmse'])\n","\n","# Perform hyperparameter tuning with GridSearchCV for SVD++\n","gs_svdpp = GridSearchCV(SVDpp, param_grid_svdpp, measures=['rmse', 'mae'], cv=5)\n","gs_svdpp.fit(data)\n","\n","# Print the best hyperparameters and RMSE for SVD++\n","print(\"SVD++ Best RMSE:\", gs_svdpp.best_score['rmse'])\n","print(\"SVD++ Best MAE:\", gs_svdpp.best_score['mae'])\n","print(\"SVD++ Best Params:\", gs_svdpp.best_params['rmse'])\n","\n","# Train and evaluate the best SVD model using cross-validation\n","best_svd = gs_svd.best_estimator['rmse']\n","cross_validate(best_svd, data, measures=['RMSE', 'MAE'], cv=5, verbose=True)\n","\n","# Train and evaluate the best SVD++ model using cross-validation\n","best_svdpp = gs_svdpp.best_estimator['rmse']\n","cross_validate(best_svdpp, data, measures=['RMSE', 'MAE'], cv=5, verbose=True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ONd9cv419Bkv","executionInfo":{"status":"ok","timestamp":1736482734943,"user_tz":-420,"elapsed":1544848,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"6819d371-c9d0-43fb-fc2d-0a309ff6e441"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["SVD Best RMSE: 0.4227881074144716\n","SVD Best MAE: 0.11731391067717534\n","SVD Best Params: {'n_factors': 150, 'n_epochs': 30, 'lr_all': 0.01, 'reg_all': 0.02}\n","SVD++ Best RMSE: 0.43099673247053455\n","SVD++ Best MAE: 0.115585997101746\n","SVD++ Best Params: {'n_factors': 50, 'n_epochs': 30, 'lr_all': 0.01, 'reg_all': 0.02}\n","Evaluating RMSE, MAE of algorithm SVD on 5 split(s).\n","\n"," Fold 1 Fold 2 Fold 3 Fold 4 Fold 5 Mean Std \n","RMSE (testset) 0.4125 0.4154 0.4399 0.4388 0.4486 0.4310 0.0144 \n","MAE (testset) 0.1189 0.1166 0.1197 0.1230 0.1215 0.1199 0.0022 \n","Fit time 2.58 3.69 2.88 2.62 2.63 2.88 0.42 \n","Test time 0.47 0.21 0.13 0.15 0.45 0.28 0.15 \n","Evaluating RMSE, MAE of algorithm SVDpp on 5 split(s).\n","\n"," Fold 1 Fold 2 Fold 3 Fold 4 Fold 5 Mean Std \n","RMSE (testset) 0.4212 0.4261 0.4266 0.4501 0.4262 0.4300 0.0102 \n","MAE (testset) 0.1168 0.1148 0.1166 0.1220 0.1138 0.1168 0.0028 \n","Fit time 21.13 19.60 21.21 21.66 19.67 20.65 0.85 \n","Test time 1.58 1.81 1.70 1.58 1.50 1.64 0.11 \n"]},{"output_type":"execute_result","data":{"text/plain":["{'test_rmse': array([0.42116177, 0.42608143, 0.42663834, 0.45007444, 0.42619555]),\n"," 'test_mae': array([0.11682776, 0.11483491, 0.11662314, 0.12203263, 0.11383799]),\n"," 'fit_time': (21.12747883796692,\n"," 19.59500551223755,\n"," 21.213244915008545,\n"," 21.66492986679077,\n"," 19.674121856689453),\n"," 'test_time': (1.5773656368255615,\n"," 1.8139982223510742,\n"," 1.6955671310424805,\n"," 1.5843687057495117,\n"," 1.504225254058838)}"]},"metadata":{},"execution_count":14}]},{"cell_type":"code","source":["# prompt: Load model using joblib from /content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/models/previous/svd_model.pkl\n","\n","import pandas as pd\n","from surprise import SVD, SVDpp\n","from surprise import Dataset, Reader\n","from surprise.model_selection import GridSearchCV, cross_validate\n","import joblib\n","\n","best_svd = joblib.load('/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/models/previous/svd_model.pkl')\n","best_svdpp = joblib.load('/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/models/previous/svdpp_model.pkl')"],"metadata":{"id":"CZZ4J7i7AuNG"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# prompt: Apply train test split # Create a pandas DataFrame from user_bundle_histories\n","from surprise.model_selection import train_test_split\n","\n","df = pd.DataFrame(user_bundle_histories)\n","# Define the rating scale for the Surprise library\n","reader = Reader(rating_scale=(0, 5))\n","# Load the data into Surprise Dataset format\n","data = Dataset.load_from_df(df[['user_id', 'bundle_id', 'rating']], reader)\n","\n","# Split the data into training and testing sets\n","trainset, testset = train_test_split(data, test_size=0.2)"],"metadata":{"id":"O4lvXLhDBmz-"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# Example usage: predict rating for a user and bundle\n","user_id_example = df['user_id'].iloc[4]\n","bundle_id_example = df['bundle_id'].iloc[4]\n","\n","svd_prediction = best_svd.predict(user_id_example, bundle_id_example)\n","svdpp_prediction = best_svdpp.predict(user_id_example, bundle_id_example)\n","\n","print(f\"SVD prediction for user {user_id_example} and bundle {bundle_id_example}: {svd_prediction.est}\")\n","print(f\"SVD++ prediction for user {user_id_example} and bundle {bundle_id_example}: {svdpp_prediction.est}\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"hsLJ7vCx-avt","executionInfo":{"status":"ok","timestamp":1736565408053,"user_tz":-420,"elapsed":334,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"b92a4dab-17b4-4929-e8cd-fa5de4068a96"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["SVD prediction for user 76561197970982479 and bundle 237: 0\n","SVD++ prediction for user 76561197970982479 and bundle 237: 0\n"]}]},{"cell_type":"code","source":["# Save the SVD model\n","import joblib\n","joblib.dump(best_svd, f\"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/models/previous/svd_model.pkl\")\n","joblib.dump(best_svdpp, f\"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/models/previous/svdpp_model.pkl\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"F9tuPy2R-sLY","executionInfo":{"status":"ok","timestamp":1736484176384,"user_tz":-420,"elapsed":6651,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"3ffcc434-5d4f-4edf-d512-00de3164ad5e"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["['/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/models/previous/svdpp_model.pkl']"]},"metadata":{},"execution_count":16}]},{"cell_type":"markdown","source":["### Do Recommendation"],"metadata":{"id":"ScY_bk_GLsxk"}},{"cell_type":"code","source":["# prompt: Convert to dictionary users bundles for variable testset\n","\n","testset = [{'user_id': entry['user_id'], 'bundle_id': entry['bundle_id'], 'rating': entry['rating']} for entry in user_bundle_histories]"],"metadata":{"id":"y_DMhiEeGIOU"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# prompt: group testset by user_id as dictionary\n","\n","from collections import defaultdict\n","\n","def group_testset_by_user(testset):\n"," \"\"\"Groups the testset by user_id.\n","\n"," Args:\n"," testset: A list of dictionaries, where each dictionary represents a data point\n"," and contains 'user_id', 'bundle_id', and 'rating' keys.\n","\n"," Returns:\n"," A dictionary where keys are user IDs and values are lists of dictionaries\n"," containing bundle IDs and ratings for that user.\n"," \"\"\"\n"," grouped_data = {}\n"," for entry in testset:\n"," user_id = entry['user_id']\n"," if user_id not in grouped_data:\n"," grouped_data[user_id] = set()\n"," grouped_data[user_id].add(entry['bundle_id'])\n"," return grouped_data\n","\n","# Example usage (assuming user_bundle_histories is defined as in the provided code)\n","grouped_testset = group_testset_by_user(user_bundle_histories)\n","\n","# Accessing data for a specific user:\n","# user_id = 'some_user_id'\n","# if user_id in grouped_testset:\n","# print(grouped_testset[user_id])"],"metadata":{"id":"WDEDrAgqGWob"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["bundle_recommendations_svd = {}\n","bundle_recommendations_svdpp = {}\n","\n","for user_id, recommendations in data_bundle_interactions.items():\n"," if user_id in user_item_dict:\n"," bundle_recommendations_svd[user_id] = {\n"," \"user_id\": user_id,\n"," \"rec_bundles\": {}\n"," }\n"," bundle_recommendations_svdpp[user_id] = {\n"," \"user_id\": user_id,\n"," \"rec_bundles\": {}\n"," }\n"," for bundle_id, recommendation in bundle_data.items():\n"," svd_prediction = best_svd.predict(user_id, bundle_id)\n"," svdpp_prediction = best_svdpp.predict(user_id, bundle_id)\n"," bundle_recommendations_svd[user_id][\"rec_bundles\"][bundle_id] = svd_prediction.est\n"," bundle_recommendations_svdpp[user_id][\"rec_bundles\"][bundle_id] = svdpp_prediction.est"],"metadata":{"id":"E9RiQapKKyMi"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# prompt: save bundle_recommendations_svd and bundle_recommendations_svdpp to /content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Recommendations/previous\n","\n","import joblib\n","\n","# Assuming bundle_recommendations_svd and bundle_recommendations_svdpp are defined\n","\n","# Save the dictionaries to separate files\n","output_dir = \"/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Recommendations/previous\"\n","joblib.dump(bundle_recommendations_svd, f\"{output_dir}/bundle_recommendations_svd.pkl\")\n","joblib.dump(bundle_recommendations_svdpp, f\"{output_dir}/bundle_recommendations_svdpp.pkl\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"kJzG-UZZU4sZ","executionInfo":{"status":"ok","timestamp":1736484442049,"user_tz":-420,"elapsed":105131,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"b77c33ae-4462-47ed-f0c2-d3bbb20922ca"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["['/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Recommendations/previous/bundle_recommendations_svdpp.pkl']"]},"metadata":{},"execution_count":20}]},{"cell_type":"code","source":["bundle_recommendations_svd['05041129']['rec_bundles']"],"metadata":{"id":"68yOSlAzRr0_"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# prompt: get top rec_bundles from data_dict with variation TOP 5 until top 20 with space 5\n","\n","def get_top_rec_bundles(data_dict, start=5, end=20, step=5):\n"," \"\"\"\n"," Gets top recommended bundles from data_dict with variations.\n","\n"," Args:\n"," data_dict: A dictionary containing recommendation data.\n"," start: The starting rank of top bundles.\n"," end: The ending rank of top bundles.\n"," step: The increment in rank.\n","\n"," Returns:\n"," A list of dictionaries, where each dictionary contains the user ID and top recommended bundles for a specified range.\n"," Returns an empty list if 'rec_bundles' key not found in data_dict.\n"," \"\"\"\n","\n"," if 'rec_bundles' not in data_dict:\n"," return []\n","\n"," results = []\n"," for top_n in range(start, end + 1, step):\n"," top_bundles = dict(sorted(data_dict['rec_bundles'].items(), key=lambda item: item[1], reverse=True)[:top_n])\n"," results.append({\"user_id\": data_dict['user_id'], \"top_rec_bundles\": top_bundles, \"top_n\": top_n})\n"," return results\n","\n","# Example usage (assuming data_dict is defined as in the provided code)\n","# Assuming data_dict contains the following:\n","# data_dict = {\"user_id\": 123, \"rec_bundles\": {\"bundle_1\": 0.9, \"bundle_2\": 0.8, \"bundle_3\": 0.7, \"bundle_4\": 0.6, \"bundle_5\": 0.5, \"bundle_6\": 0.4, \"bundle_7\": 0.3, \"bundle_8\":0.2, \"bundle_9\":0.1, \"bundle_10\": 0.0}}\n","\n","top_bundles_results = get_top_rec_bundles(bundle_recommendations_svd['05041129'])\n","\n","for result in top_bundles_results:\n"," print(f\"Top {result['top_n']} recommended bundles for user {result['user_id']}:\")\n"," print(result['top_rec_bundles'])\n"," print(\"-\" * 20)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"flYvFh9kThB6","executionInfo":{"status":"ok","timestamp":1736566037797,"user_tz":-420,"elapsed":315,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"6e27772e-c05c-4df2-f272-a7a1aa9ff86e"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Top 5 recommended bundles for user 05041129:\n","{'236': 4.58394644822258, '232': 4.450175094671308, '779': 1.2538914930131972, '1373': 1.153043238103371, '273': 1.11762194663225}\n","--------------------\n","Top 10 recommended bundles for user 05041129:\n","{'236': 4.58394644822258, '232': 4.450175094671308, '779': 1.2538914930131972, '1373': 1.153043238103371, '273': 1.11762194663225, '746': 1.1054268718330793, '837': 1.0987879634869864, '778': 0.992210387729151, '1208': 0.9838027523112424, '336': 0.968144804258227}\n","--------------------\n","Top 15 recommended bundles for user 05041129:\n","{'236': 4.58394644822258, '232': 4.450175094671308, '779': 1.2538914930131972, '1373': 1.153043238103371, '273': 1.11762194663225, '746': 1.1054268718330793, '837': 1.0987879634869864, '778': 0.992210387729151, '1208': 0.9838027523112424, '336': 0.968144804258227, '340': 0.9596856608050313, '718': 0.9464258486809938, '471': 0.9388995808241061, '1352': 0.8837189877221086, '245': 0.8768343404645818}\n","--------------------\n","Top 20 recommended bundles for user 05041129:\n","{'236': 4.58394644822258, '232': 4.450175094671308, '779': 1.2538914930131972, '1373': 1.153043238103371, '273': 1.11762194663225, '746': 1.1054268718330793, '837': 1.0987879634869864, '778': 0.992210387729151, '1208': 0.9838027523112424, '336': 0.968144804258227, '340': 0.9596856608050313, '718': 0.9464258486809938, '471': 0.9388995808241061, '1352': 0.8837189877221086, '245': 0.8768343404645818, '1138': 0.865768559555006, '15': 0.8646955964450294, '1140': 0.8627168807592118, '871': 0.850707424409803, '285': 0.8168487934929798}\n","--------------------\n"]}]},{"cell_type":"code","source":["top_bundles_results"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ZaKabLfoMT79","executionInfo":{"status":"ok","timestamp":1736495416549,"user_tz":-420,"elapsed":315,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"663072af-793e-4c2e-e2f2-b0ae843f1e0c","collapsed":true},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[{'user_id': '76561198039327637',\n"," 'top_rec_bundles': {'1373': 0.57700419949448,\n"," '1208': 0.46659130244267333,\n"," '285': 0.4516739555225235,\n"," '417': 0.39634801114642193,\n"," '284': 0.3711011812201989},\n"," 'top_n': 5},\n"," {'user_id': '76561198039327637',\n"," 'top_rec_bundles': {'1373': 0.57700419949448,\n"," '1208': 0.46659130244267333,\n"," '285': 0.4516739555225235,\n"," '417': 0.39634801114642193,\n"," '284': 0.3711011812201989,\n"," '274': 0.348557396310978,\n"," '1340': 0.33219701307626803,\n"," '1336': 0.3313216658302862,\n"," '1392': 0.3166953015218182,\n"," '1477': 0.30648172691321063},\n"," 'top_n': 10},\n"," {'user_id': '76561198039327637',\n"," 'top_rec_bundles': {'1373': 0.57700419949448,\n"," '1208': 0.46659130244267333,\n"," '285': 0.4516739555225235,\n"," '417': 0.39634801114642193,\n"," '284': 0.3711011812201989,\n"," '274': 0.348557396310978,\n"," '1340': 0.33219701307626803,\n"," '1336': 0.3313216658302862,\n"," '1392': 0.3166953015218182,\n"," '1477': 0.30648172691321063,\n"," '837': 0.2885112052176223,\n"," '836': 0.280917999017427,\n"," '496': 0.27426196581305284,\n"," '166': 0.2692156490220411,\n"," '516': 0.2599261998891152},\n"," 'top_n': 15},\n"," {'user_id': '76561198039327637',\n"," 'top_rec_bundles': {'1373': 0.57700419949448,\n"," '1208': 0.46659130244267333,\n"," '285': 0.4516739555225235,\n"," '417': 0.39634801114642193,\n"," '284': 0.3711011812201989,\n"," '274': 0.348557396310978,\n"," '1340': 0.33219701307626803,\n"," '1336': 0.3313216658302862,\n"," '1392': 0.3166953015218182,\n"," '1477': 0.30648172691321063,\n"," '837': 0.2885112052176223,\n"," '836': 0.280917999017427,\n"," '496': 0.27426196581305284,\n"," '166': 0.2692156490220411,\n"," '516': 0.2599261998891152,\n"," '273': 0.2580370742043224,\n"," '462': 0.24488578655997226,\n"," '1156': 0.23804384583782556,\n"," '243': 0.23242754858394987,\n"," '264': 0.22748889019619434},\n"," 'top_n': 20}]"]},"metadata":{},"execution_count":52}]},{"cell_type":"code","source":["grouped_testset['117arbiter']"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"mMbxE_HNGjRW","executionInfo":{"status":"ok","timestamp":1736494112386,"user_tz":-420,"elapsed":281,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"7a4d8fd8-32a5-4953-ba0a-669650cdf8ff","collapsed":true},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["{'1144',\n"," '1158',\n"," '1190',\n"," '1229',\n"," '1246',\n"," '1336',\n"," '1340',\n"," '139',\n"," '1399',\n"," '1468',\n"," '231',\n"," '232',\n"," '233',\n"," '234',\n"," '241',\n"," '248',\n"," '257',\n"," '312',\n"," '362',\n"," '383',\n"," '396',\n"," '572',\n"," '604',\n"," '612',\n"," '616',\n"," '635',\n"," '646',\n"," '712',\n"," '727',\n"," '803',\n"," '813',\n"," '957'}"]},"metadata":{},"execution_count":47}]},{"cell_type":"markdown","source":["### Evaluation"],"metadata":{"id":"fbCasxBUTgRk"}},{"cell_type":"code","source":["# prompt: Calculate hit_ratio from top_bundles_results by calculating how many items from user_item_interactions is on bundle_data by bundle_id and item_id\n","\n","def calculate_hit_ratio(top_bundles_results, grouped_testset):\n"," \"\"\"\n"," Calculates the hit ratio based on the provided data.\n","\n"," Args:\n"," top_bundles_results: A list of dictionaries, where each dictionary contains user ID and top recommended bundles.\n"," user_item_interactions: A dictionary mapping user IDs to their item interactions.\n"," bundle_data: A dictionary mapping bundle IDs to their items.\n","\n"," Returns:\n"," A list of dictionaries, each containing the user ID, top N, and hit ratio.\n"," \"\"\"\n","\n"," hit = {}\n"," for user_id2 in grouped_testset:\n"," data_test = grouped_testset[user_id2]\n"," temp_hit = {}\n"," for bundle_id_test in data_test:\n"," for result in top_bundles_results:\n"," top_n = result['top_n']\n"," top_bundles = result['top_rec_bundles']\n","\n"," if top_n not in temp_hit:\n"," temp_hit[top_n] = 0\n","\n"," if bundle_id_test in top_bundles:\n"," temp_hit[top_n] += 1\n","\n"," for top_n, count in temp_hit.items():\n"," if top_n not in hit:\n"," hit[top_n] = 0\n"," hit[top_n] += (count / len(data_test))\n","\n"," hit_ratios = {}\n"," for top_n, count in hit.items():\n"," hit_ratios[top_n] = count / len(grouped_testset)\n","\n"," return hit_ratios\n","\n","# Example usage (assuming the necessary data structures are defined):\n","hit_ratios = calculate_hit_ratio(top_bundles_results, grouped_testset)\n","hit_ratios"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"hfTbC2xdTWNg","executionInfo":{"status":"ok","timestamp":1736566418051,"user_tz":-420,"elapsed":297,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"d132c1ac-218a-4130-9c3c-cfdc96eb3b02"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["{5: 0.15767951752885323,\n"," 10: 0.15909343974655227,\n"," 15: 0.15968104269273362,\n"," 20: 0.15983777478434272}"]},"metadata":{},"execution_count":28}]},{"cell_type":"code","source":["# prompt: Calculate Gini-Simpson Diversity Index using top_bundles_results and grouped_testset based on varible bundle_tags bundle_specs for each bundle_id that recommended\n","\n","import pandas as pd\n","\n","def calculate_gini_simpson_index(top_bundles_results, grouped_testset, bundle_tags, bundle_specs):\n"," \"\"\"\n"," Calculates the Gini-Simpson diversity index for recommended bundles.\n","\n"," Args:\n"," top_bundles_results: Results from get_top_rec_bundles function.\n"," grouped_testset: User's interaction data grouped by user.\n"," bundle_tags: Dictionary of bundle tags.\n"," bundle_specs: Dictionary of bundle specs.\n","\n"," Returns:\n"," A dictionary containing Gini-Simpson index for each user and top_n.\n"," \"\"\"\n","\n"," gini_simpson_indices = {}\n","\n"," for result in top_bundles_results:\n"," user_id = result['user_id']\n"," top_n = result['top_n']\n"," top_bundles = result['top_rec_bundles']\n","\n"," if top_n not in gini_simpson_indices:\n"," gini_simpson_indices[top_n] = 0.0\n","\n"," # Combine tags and specs for each bundle\n"," combined_features = {}\n"," for bundle_id in top_bundles:\n"," combined_features[bundle_id] = {}\n"," if bundle_id in bundle_tags:\n"," combined_features[bundle_id].update(bundle_tags[bundle_id])\n"," if bundle_id in bundle_specs:\n"," combined_features[bundle_id].update(bundle_specs[bundle_id])\n","\n"," # Calculate probabilities for each feature\n"," total_features = {}\n"," for bundle_id in combined_features:\n"," total_features[bundle_id] = {}\n"," for feature, count in combined_features[bundle_id].items():\n"," if feature not in total_features:\n"," total_features[bundle_id][feature] = 1\n","\n"," all_features = set()\n"," for bundle_id in combined_features:\n"," for feature, count in combined_features[bundle_id].items():\n"," if feature not in all_features:\n"," all_features.add(feature)\n","\n"," probabilities = {}\n"," for feature in all_features:\n"," probabilities[feature] = 0\n"," for bundle_id in combined_features:\n"," if feature in combined_features[bundle_id]:\n"," probabilities[feature] += 1\n","\n"," probabilities[feature] = probabilities[feature] / len(combined_features)\n","\n"," # Calculate Gini-Simpson index\n"," gini_simpson_index = 1 - (sum(p**2 for p in probabilities.values()) / len(probabilities))\n"," gini_simpson_indices[top_n] = gini_simpson_index\n","\n"," return gini_simpson_indices\n","\n","# Example usage (assuming necessary data structures are defined)\n","gini_simpson_result = calculate_gini_simpson_index(top_bundles_results, grouped_testset, bundle_tags, bundle_specs)\n","gini_simpson_result"],"metadata":{"id":"-MwuwWdpU7ZY","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1736571082901,"user_tz":-420,"elapsed":338,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"4688110a-e29d-405c-996e-856a6faede27"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["{5: 0.8561702127659574,\n"," 10: 0.9006024096385543,\n"," 15: 0.9138833883388339,\n"," 20: 0.928235294117647}"]},"metadata":{},"execution_count":56}]},{"cell_type":"code","source":["import json\n","import gzip\n","import ast\n","\n","# Open the gzipped file\n","data_dict = None\n","# filepath_rarank_rec_data = '/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Recommendations/previous/mf_bundles.json.gz'\n","\n","average_hit_ratio = {}\n","average_diversity = {}\n","count = 0\n","\n","top_bundles_results = []\n","hit_ratios = []\n","diversity_scores = []\n","\n","for user_id, bundle_recommendations in bundle_recommendations_svd.items():\n","\n"," top_bundles_results = get_top_rec_bundles(bundle_recommendations)\n"," hit_ratios = calculate_hit_ratio(top_bundles_results, grouped_testset)\n"," diversity_scores = calculate_gini_simpson_index(top_bundles_results, grouped_testset, bundle_tags, bundle_specs)\n","\n"," average_hit_ratio[bundle_recommendations['user_id']] = hit_ratios\n"," average_diversity[bundle_recommendations['user_id']] = diversity_scores"],"metadata":{"id":"_CvOgzRCUDNS"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["import json\n","import gzip\n","import ast\n","\n","# Open the gzipped file\n","data_dict = None\n","# filepath_rarank_rec_data = '/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Recommendations/previous/mf_bundles.json.gz'\n","\n","average_hit_ratio = {}\n","average_diversity = {}\n","count = 0\n","\n","top_bundles_results = []\n","hit_ratios = []\n","diversity_scores = []\n","\n","for user_id, bundle_recommendations in bundle_recommendations_svdpp.items():\n","\n"," top_bundles_results = get_top_rec_bundles(bundle_recommendations)\n"," hit_ratios = calculate_hit_ratio(top_bundles_results, grouped_testset)\n"," diversity_scores = calculate_gini_simpson_index(top_bundles_results, grouped_testset, bundle_tags, bundle_specs)\n","\n"," average_hit_ratio[bundle_recommendations['user_id']] = hit_ratios\n"," average_diversity[bundle_recommendations['user_id']] = diversity_scores\n"],"metadata":{"id":"tJW7duLzbMJj"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# prompt: calculate mean from average_hit_ratio\n","\n","import numpy as np\n","\n","# Assuming average_hit_ratio is a dictionary where keys are user IDs and values are dictionaries of hit ratios for different top_n values.\n","# Example: average_hit_ratio = {'user1': {5: 0.2, 10: 0.3}, 'user2': {5: 0.1, 10: 0.2}}\n","\n","def calculate_mean_hit_ratio(average_hit_ratio):\n"," \"\"\"Calculates the mean hit ratio across all users and top_n values.\n","\n"," Args:\n"," average_hit_ratio: A dictionary containing hit ratios for different users and top_n values.\n","\n"," Returns:\n"," The mean hit ratio as a float. Returns 0 if input dictionary is empty or contains no valid hit ratios.\n"," \"\"\"\n"," all_hit_ratios = {}\n"," for user_id, hit_ratios in average_hit_ratio.items():\n"," for top_n, hit_ratio in hit_ratios.items():\n"," if top_n not in all_hit_ratios:\n"," all_hit_ratios[top_n] = []\n"," all_hit_ratios[top_n].append(hit_ratio)\n","\n"," if not all_hit_ratios:\n"," return 0\n","\n"," new_hit_ratios = {}\n"," for top_n, hit_ratios in all_hit_ratios.items():\n"," new_hit_ratios[top_n] = np.mean(hit_ratios)\n","\n"," return new_hit_ratios\n","\n","# Example usage:\n","mean_hit_ratio = calculate_mean_hit_ratio(average_hit_ratio)\n","print(f\"Mean Hit Ratio: {mean_hit_ratio}\")\n","mean_diversity = calculate_mean_hit_ratio(average_diversity)\n","print(f\"Mean Diversity: {mean_diversity}\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"jtl6g8BPW1hg","executionInfo":{"status":"ok","timestamp":1736572250005,"user_tz":-420,"elapsed":337,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"c72fc83d-9484-4dca-cdc7-44621eb53f5f"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Mean Hit Ratio: {5: 0.018696515078579508, 10: 0.02914531265888084, 15: 0.044024473936550075, 20: 0.06400405595420844}\n","Mean Diversity: {5: 0.8563891379271561, 10: 0.91239270055999, 15: 0.9296749412996965, 20: 0.9385664697012452}\n"]}]},{"cell_type":"code","source":["# prompt: combine average_hit_ratio_df, average_intra_diversity_df, average_inter_diversity_df and make it colomn like top_n | hit_ratio | intra_diversity | inter_diversity just create from dictionary do not using merge function of pandas\n","\n","import pandas as pd\n","\n","def combine_metrics(mean_hit_ratio, mean_diversity):\n"," \"\"\"Combines the three dataframes into a single columnar dataframe.\n"," \"\"\"\n"," combined_data = []\n"," for top_n in mean_hit_ratio:\n"," row = {\n"," 'top_n': top_n,\n"," 'hit_ratio': mean_hit_ratio[top_n],\n"," 'diversity': mean_diversity[top_n],\n"," }\n"," combined_data.append(row)\n"," return pd.DataFrame(combined_data)\n","\n","# Example usage (assuming the three dataframes are available):\n","combined_df = combine_metrics(mean_hit_ratio, mean_diversity)\n","combined_df"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":175},"id":"kpWLqx-_asIk","executionInfo":{"status":"ok","timestamp":1736572257619,"user_tz":-420,"elapsed":492,"user":{"displayName":"Fundamental RecSys","userId":"12384593251438087944"}},"outputId":"2e9de219-d3ba-4bf1-ecde-4b7c80ea8635"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" top_n hit_ratio diversity\n","0 5 0.018697 0.856389\n","1 10 0.029145 0.912393\n","2 15 0.044024 0.929675\n","3 20 0.064004 0.938566"],"text/html":["\n","
\n","
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
top_nhit_ratiodiversity
050.0186970.856389
1100.0291450.912393
2150.0440240.929675
3200.0640040.938566
\n","
\n","
\n","\n","
\n"," \n","\n"," \n","\n"," \n","
\n","\n","\n","
\n"," \n","\n","\n","\n"," \n","
\n","\n","
\n"," \n"," \n"," \n","
\n","\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"combined_df","summary":"{\n \"name\": \"combined_df\",\n \"rows\": 4,\n \"fields\": [\n {\n \"column\": \"top_n\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 6,\n \"min\": 5,\n \"max\": 20,\n \"num_unique_values\": 4,\n \"samples\": [\n 10,\n 20,\n 5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"hit_ratio\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.019662064263107275,\n \"min\": 0.018696515078579508,\n \"max\": 0.06400405595420844,\n \"num_unique_values\": 4,\n \"samples\": [\n 0.02914531265888084,\n 0.06400405595420844,\n 0.018696515078579508\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"diversity\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.03688170636688508,\n \"min\": 0.8563891379271561,\n \"max\": 0.9385664697012452,\n \"num_unique_values\": 4,\n \"samples\": [\n 0.91239270055999,\n 0.9385664697012452,\n 0.8563891379271561\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":63}]},{"cell_type":"code","source":["# prompt: save combined_df as /content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Evaluation/tags_and_specs_native.csv\n","\n","# combined_df.to_csv('/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Evaluation/previous/bundle_recommendation_svd.csv', index=False)\n","combined_df.to_csv('/content/drive/MyDrive/Projects/Disertation/SOTA Bundle Matching/Evaluation/previous/bundle_recommendation_svdpp.csv', index=False)"],"metadata":{"id":"JImcjAVFawOX"},"execution_count":null,"outputs":[]}]}