{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# OTTO – Multi-Objective Recommender System\n#### Build a recommender system based on real-world e-commerce sessions\n========================================================================\n\n**Aim:** \n    The goal of this competition is to predict e-commerce clicks, cart additions, and orders. You'll build a multi-objective recommender system based on previous events in a user session.\n\n**What we build:**\n    Build a single entry to predict click-through, add-to-cart, and conversion rates based on previous same-session events\n\n**Outcome:**\n    Your work will help improve the shopping experience for everyone involved. Customers will receive more tailored recommendations while online retailers may increase their sales.\n    \nYour work will help online retailers select more relevant items from a vast range to recommend to their customers based on their real-time behavior. Improving recommendations will ensure navigating through seemingly endless options is more effortless and engaging for shoppers.\n\n**Evaluation:**\n\nSubmissions are evaluated on Recall@20 for each action type, and the three recall values are weight-averaged:\n\n$𝑠𝑐𝑜𝑟𝑒=0.10⋅𝑅𝑐𝑙𝑖𝑐𝑘𝑠+0.30⋅𝑅𝑐𝑎𝑟𝑡𝑠+0.60⋅𝑅𝑜𝑟𝑑𝑒𝑟𝑠$\n\nwhere 𝑅 is defined as\n\n$\\frac{𝑅𝑡𝑦𝑝𝑒=∑^{𝑁}_{𝑖}|\\{predicted aids\\}_{𝑖,𝑡𝑦𝑝𝑒}∩\\{ground truth aids\\}_{𝑖,𝑡𝑦𝑝𝑒}|}{∑^{𝑁}_{𝑖}min(20,|\\{ground truth aids\\}_{𝑖,𝑡𝑦𝑝𝑒}|)}$\n\nand 𝑁 is the total number of sessions in the test set, and predicted aids are the predictions for each session-type (e.g., each row in the submission file) truncated after the first 20 predictions.\n    \n![alt-text](https://github.com/otto-de/recsys-dataset/blob/main/.readme/ground_truth.png?raw=true)\n\n\nFor each session id and type combination in the test set, you must predict the aid values in the label column\n\n```\nsession_type,labels\n12906577_clicks,135193 129431 119318 ...\n12906577_carts,135193 129431 119318 ...\n```","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom fastai.tabular.all import *\nfrom fastai.collab import *","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:19:07.684643Z","iopub.execute_input":"2022-12-06T14:19:07.685098Z","iopub.status.idle":"2022-12-06T14:19:10.607383Z","shell.execute_reply.started":"2022-12-06T14:19:07.685049Z","shell.execute_reply":"2022-12-06T14:19:10.606215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_parquet('../input/otto-train-and-test-data-for-local-validation/test.parquet')","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:19:12.796236Z","iopub.execute_input":"2022-12-06T14:19:12.797011Z","iopub.status.idle":"2022-12-06T14:19:14.019999Z","shell.execute_reply.started":"2022-12-06T14:19:12.796962Z","shell.execute_reply":"2022-12-06T14:19:14.018479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_df = train.sample(n=100000, replace='False')\ntrain_df = train.iloc[:100000, :]","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:42:00.929702Z","iopub.execute_input":"2022-12-06T14:42:00.930162Z","iopub.status.idle":"2022-12-06T14:42:00.935627Z","shell.execute_reply.started":"2022-12-06T14:42:00.930122Z","shell.execute_reply":"2022-12-06T14:42:00.934696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:42:01.989169Z","iopub.execute_input":"2022-12-06T14:42:01.989595Z","iopub.status.idle":"2022-12-06T14:42:02.009782Z","shell.execute_reply.started":"2022-12-06T14:42:01.989558Z","shell.execute_reply":"2022-12-06T14:42:02.008880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_df)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:42:04.388041Z","iopub.execute_input":"2022-12-06T14:42:04.388479Z","iopub.status.idle":"2022-12-06T14:42:04.396529Z","shell.execute_reply.started":"2022-12-06T14:42:04.388440Z","shell.execute_reply":"2022-12-06T14:42:04.395498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls = CollabDataLoaders.from_df(train_df, user_name='session', item_name='aid', bs=64, shuffle=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:42:50.910033Z","iopub.execute_input":"2022-12-06T14:42:50.910478Z","iopub.status.idle":"2022-12-06T14:42:51.098322Z","shell.execute_reply.started":"2022-12-06T14:42:50.910431Z","shell.execute_reply":"2022-12-06T14:42:51.097225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls.show_batch()","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:42:54.918030Z","iopub.execute_input":"2022-12-06T14:42:54.918462Z","iopub.status.idle":"2022-12-06T14:42:54.988457Z","shell.execute_reply.started":"2022-12-06T14:42:54.918424Z","shell.execute_reply":"2022-12-06T14:42:54.987520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = collab_learner(dls, n_factors=10)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:43:26.145795Z","iopub.execute_input":"2022-12-06T14:43:26.146234Z","iopub.status.idle":"2022-12-06T14:43:26.174083Z","shell.execute_reply.started":"2022-12-06T14:43:26.146195Z","shell.execute_reply":"2022-12-06T14:43:26.173144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn.fit_one_cycle(15)","metadata":{"execution":{"iopub.status.busy":"2022-12-06T14:43:32.871120Z","iopub.execute_input":"2022-12-06T14:43:32.871552Z","iopub.status.idle":"2022-12-06T14:46:35.436571Z","shell.execute_reply.started":"2022-12-06T14:43:32.871511Z","shell.execute_reply":"2022-12-06T14:46:35.435560Z"},"trusted":true},"execution_count":null,"outputs":[]}]}