{"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":"The goal of the competition is to build a recommender system that recommends the user's next action.\n\nAs part of this notebook we will load a small sample of the total data and try to create insightful visualizations.","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-03T02:51:13.964509Z","iopub.execute_input":"2022-11-03T02:51:13.965316Z","iopub.status.idle":"2022-11-03T02:51:16.509447Z","shell.execute_reply.started":"2022-11-03T02:51:13.965220Z","shell.execute_reply":"2022-11-03T02:51:16.508203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code reference to read json data into pandas: \n#https://www.kaggle.com/code/edwardcrookenden/otto-getting-started-eda-baseline\nTRAIN_PATH = '../input/otto-recommender-system/train.jsonl'\nsample_size = 150000\n\nchunks = pd.read_json(TRAIN_PATH, lines=True, chunksize = sample_size)\n\nfor c in chunks:\n    sample_train_df = c\n    break","metadata":{"execution":{"iopub.status.busy":"2022-11-03T02:51:16.511548Z","iopub.execute_input":"2022-11-03T02:51:16.511946Z","iopub.status.idle":"2022-11-03T02:51:28.336980Z","shell.execute_reply.started":"2022-11-03T02:51:16.511913Z","shell.execute_reply":"2022-11-03T02:51:28.336043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_train_df.set_index('session', drop=True, inplace=True)\nsample_train_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-03T02:51:28.338164Z","iopub.execute_input":"2022-11-03T02:51:28.338570Z","iopub.status.idle":"2022-11-03T02:51:28.429032Z","shell.execute_reply.started":"2022-11-03T02:51:28.338546Z","shell.execute_reply":"2022-11-03T02:51:28.428415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's look at the number of article ids in our sample events.","metadata":{}},{"cell_type":"code","source":"length_of_sample_events = []\nfor i in sample_train_df[\"events\"]:\n    length_of_sample_events.append(len(i))","metadata":{"execution":{"iopub.status.busy":"2022-11-03T02:51:28.430404Z","iopub.execute_input":"2022-11-03T02:51:28.430729Z","iopub.status.idle":"2022-11-03T02:51:28.499128Z","shell.execute_reply.started":"2022-11-03T02:51:28.430707Z","shell.execute_reply":"2022-11-03T02:51:28.498068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.histogram(x = length_of_sample_events,marginal=\"box\", title=\"Distribution of number of actions performed in a single event\")","metadata":{"execution":{"iopub.status.busy":"2022-11-03T02:51:28.500391Z","iopub.execute_input":"2022-11-03T02:51:28.500622Z","iopub.status.idle":"2022-11-03T02:51:29.952762Z","shell.execute_reply.started":"2022-11-03T02:51:28.500600Z","shell.execute_reply":"2022-11-03T02:51:29.951470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Insights:\n\nIn a single event the max number of actions performed are 495 which seems too be a little to excessive to me.\n\nThe median number of actions in an event are 19 which seems plausible.","metadata":{}},{"cell_type":"markdown","source":"Distribution of the event types in our sample","metadata":{}},{"cell_type":"code","source":"total_clicks,total_orders,total_carts = [],[],[]\nfor i in sample_train_df[\"events\"]:\n    evnt_clicks,evnt_orders,evnt_carts = 0,0,0\n    for j in i:\n        if j[\"type\"] == \"clicks\":\n            evnt_clicks += 1\n        elif j[\"type\"] == \"orders\":\n            evnt_orders += 1\n        else:\n            evnt_carts += 1\n    total_clicks.append(evnt_clicks)\n    total_orders.append(evnt_orders)\n    total_carts.append(evnt_carts)","metadata":{"execution":{"iopub.status.busy":"2022-11-03T03:10:14.816791Z","iopub.execute_input":"2022-11-03T03:10:14.817212Z","iopub.status.idle":"2022-11-03T03:10:16.509878Z","shell.execute_reply.started":"2022-11-03T03:10:14.817177Z","shell.execute_reply":"2022-11-03T03:10:16.508430Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dummy_df = pd.DataFrame()\ndummy_df['clicks'] = total_clicks\ndummy_df['orders'] = total_orders\ndummy_df['carts'] = total_carts","metadata":{"execution":{"iopub.status.busy":"2022-11-03T03:14:20.615992Z","iopub.execute_input":"2022-11-03T03:14:20.616355Z","iopub.status.idle":"2022-11-03T03:14:20.761292Z","shell.execute_reply.started":"2022-11-03T03:14:20.616328Z","shell.execute_reply":"2022-11-03T03:14:20.760550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\npx.histogram(dummy_df['clicks'],marginal=\"box\",title=\"Total No. of Clicks\")\n\n","metadata":{"execution":{"iopub.status.busy":"2022-11-03T03:38:33.771538Z","iopub.execute_input":"2022-11-03T03:38:33.771853Z","iopub.status.idle":"2022-11-03T03:38:34.745435Z","shell.execute_reply.started":"2022-11-03T03:38:33.771828Z","shell.execute_reply":"2022-11-03T03:38:34.743822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.histogram(dummy_df['orders'],marginal=\"box\",title=\"Total No. of Orders\")","metadata":{"execution":{"iopub.status.busy":"2022-11-03T03:39:28.502031Z","iopub.execute_input":"2022-11-03T03:39:28.502376Z","iopub.status.idle":"2022-11-03T03:39:28.615871Z","shell.execute_reply.started":"2022-11-03T03:39:28.502352Z","shell.execute_reply":"2022-11-03T03:39:28.614408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"px.histogram(dummy_df['carts'],marginal=\"box\",title=\"Total No. of Carts\")","metadata":{"execution":{"iopub.status.busy":"2022-11-03T03:42:57.092106Z","iopub.execute_input":"2022-11-03T03:42:57.092463Z","iopub.status.idle":"2022-11-03T03:42:57.203962Z","shell.execute_reply.started":"2022-11-03T03:42:57.092438Z","shell.execute_reply":"2022-11-03T03:42:57.202554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Insights:\n\nNumber of clicks on the site is way more than the number of orders, the median number of clicks in our sample of 150 K is 18; whereas the median number of orders is 0.\n\nThe 75th percentile of items placed in the carts in our sample is 4.\n\nThe most common action in any event of the 3 is click followed by addition to carts and the next being actual orders placed.","metadata":{}},{"cell_type":"markdown","source":"Work in progress !","metadata":{}}]}