{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-28T20:47:37.586423Z","iopub.execute_input":"2022-11-28T20:47:37.586932Z","iopub.status.idle":"2022-11-28T20:47:37.619207Z","shell.execute_reply.started":"2022-11-28T20:47:37.586826Z","shell.execute_reply":"2022-11-28T20:47:37.618031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Libs**","metadata":{}},{"cell_type":"code","source":"import torch\nfrom torch import nn\nfrom torch.utils.data import Dataset, DataLoader\n\nimport pandas as pd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2022-11-28T21:02:28.862897Z","iopub.execute_input":"2022-11-28T21:02:28.863707Z","iopub.status.idle":"2022-11-28T21:02:28.868916Z","shell.execute_reply.started":"2022-11-28T21:02:28.863655Z","shell.execute_reply":"2022-11-28T21:02:28.867749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### **Data**","metadata":{}},{"cell_type":"code","source":"sample_submission = pd.read_csv(\"/kaggle/input/otto-recommender-system/sample_submission.csv\")\nsample_submission","metadata":{"execution":{"iopub.status.busy":"2022-11-28T21:02:29.270110Z","iopub.execute_input":"2022-11-28T21:02:29.270910Z","iopub.status.idle":"2022-11-28T21:02:33.780906Z","shell.execute_reply.started":"2022-11-28T21:02:29.270872Z","shell.execute_reply":"2022-11-28T21:02:33.779861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_json(\"/kaggle/input/otto-recommender-system/train.jsonl\", lines=True,\n                          chunksize=10000)","metadata":{"execution":{"iopub.status.busy":"2022-11-28T21:02:33.783244Z","iopub.execute_input":"2022-11-28T21:02:33.783921Z","iopub.status.idle":"2022-11-28T21:02:33.790313Z","shell.execute_reply.started":"2022-11-28T21:02:33.783875Z","shell.execute_reply":"2022-11-28T21:02:33.788322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = {\n    \"session\": [],\n    \"aid\": [],\n    \"timestamp\": [],\n    \"type\": [],\n}\n\nfor i, chunk in enumerate(train_data):\n    for session, events in zip(chunk[\"session\"].tolist(), chunk[\"events\"].tolist()):\n        for event in events:\n            data[\"session\"].append(session)\n            data[\"aid\"].append(event[\"aid\"])\n            data[\"timestamp\"].append(event[\"ts\"])\n            data[\"type\"].append(event[\"type\"])\n    if i == 30:\n        break\n    \ntrain_df = pd.DataFrame(data)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-11-28T21:02:33.792106Z","iopub.execute_input":"2022-11-28T21:02:33.792566Z","iopub.status.idle":"2022-11-28T21:03:36.041758Z","shell.execute_reply.started":"2022-11-28T21:02:33.792530Z","shell.execute_reply":"2022-11-28T21:03:36.040721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.to_csv(\"/kaggle/working/train.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-11-28T21:03:36.044096Z","iopub.execute_input":"2022-11-28T21:03:36.045201Z","iopub.status.idle":"2022-11-28T21:04:06.123988Z","shell.execute_reply.started":"2022-11-28T21:03:36.045157Z","shell.execute_reply":"2022-11-28T21:04:06.122845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/working/train.csv\")\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2022-11-28T12:59:10.476822Z","iopub.execute_input":"2022-11-28T12:59:10.477239Z","iopub.status.idle":"2022-11-28T12:59:15.414926Z","shell.execute_reply.started":"2022-11-28T12:59:10.477205Z","shell.execute_reply":"2022-11-28T12:59:15.413449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sess = train_df.groupby(\"session\")[\"aid\"].apply(list)\ndf_sess","metadata":{"execution":{"iopub.status.busy":"2022-11-28T21:22:07.339405Z","iopub.execute_input":"2022-11-28T21:22:07.339837Z","iopub.status.idle":"2022-11-28T21:22:17.556804Z","shell.execute_reply.started":"2022-11-28T21:22:07.339773Z","shell.execute_reply":"2022-11-28T21:22:17.555639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class OTTODataset(Dataset):\n    def __init__(self, df):\n        super(OTTODataset, self).__init__()\n        self.df = df.copy()\n        \n    def __getitem__(self, idx):\n        pass\n    \n    def __len__(self):\n        return len(self.df)","metadata":{"execution":{"iopub.status.busy":"2022-11-28T12:59:48.207378Z","iopub.execute_input":"2022-11-28T12:59:48.207914Z","iopub.status.idle":"2022-11-28T12:59:48.215664Z","shell.execute_reply.started":"2022-11-28T12:59:48.207869Z","shell.execute_reply":"2022-11-28T12:59:48.214276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}