{"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":"# Code","metadata":{}},{"cell_type":"code","source":"# import libraries\nimport pandas as pd\nimport numpy as np\n\n# read data\ntest = pd.read_parquet('../input/otto-full-optimized-memory-footprint/test.parquet')\n\n# reverse the order of aids in each session\naid_candidates=test.groupby('session')['aid'].apply(lambda x: np.flip(np.array(x)))\n\n# create submission labels\nlabels=[]\nfor curr_aid_candidates in aid_candidates:\n    labelstr=\" \".join([str(aid) for aid in curr_aid_candidates])\n    labels.append(labelstr) # for the row \"session #_clicks\"\n    labels.append(labelstr) # for the row \"session #_carts\"\n    labels.append(labelstr) # for the row \"session #_orders\"\n\n# generate submission.csv\nsubmission = pd.read_csv('/kaggle/input/otto-recommender-system/sample_submission.csv')\nsubmission['labels']=labels\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-01-04T03:30:37.942752Z","iopub.execute_input":"2023-01-04T03:30:37.943166Z","iopub.status.idle":"2023-01-04T03:31:35.067830Z","shell.execute_reply.started":"2023-01-04T03:30:37.943133Z","shell.execute_reply":"2023-01-04T03:31:35.066214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Actually, if we directly use the original aid series as output (no sorting, no other operations), the score will be ~0.44","metadata":{}},{"cell_type":"markdown","source":"# What does the code above tells us?","metadata":{}},{"cell_type":"markdown","source":"Based on my understanding, this code illustrates a recommendation system that: given a user and the items he interacted in the current session (regradless of action types) , the system will just record these items, weight them based on reverse temporal order, and recommend them to the user. The chance that the system really recommends what the users would like to interact next is around 46% (based on my understanding of the evaluation metric)","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}