{"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\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-04-07T14:31:41.608815Z","iopub.execute_input":"2022-04-07T14:31:41.609174Z","iopub.status.idle":"2022-04-07T14:31:41.635655Z","shell.execute_reply.started":"2022-04-07T14:31:41.609085Z","shell.execute_reply":"2022-04-07T14:31:41.635005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport os\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:31:41.636730Z","iopub.execute_input":"2022-04-07T14:31:41.639011Z","iopub.status.idle":"2022-04-07T14:31:41.643236Z","shell.execute_reply.started":"2022-04-07T14:31:41.638972Z","shell.execute_reply":"2022-04-07T14:31:41.642467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers=pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/customers.csv')\ncustomers.describe()","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:31:41.644964Z","iopub.execute_input":"2022-04-07T14:31:41.645260Z","iopub.status.idle":"2022-04-07T14:31:47.130725Z","shell.execute_reply.started":"2022-04-07T14:31:41.645221Z","shell.execute_reply":"2022-04-07T14:31:47.129951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train=pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')\ntransactions_train['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:31:47.132518Z","iopub.execute_input":"2022-04-07T14:31:47.133283Z","iopub.status.idle":"2022-04-07T14:32:48.326680Z","shell.execute_reply.started":"2022-04-07T14:31:47.133236Z","shell.execute_reply":"2022-04-07T14:32:48.326040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactionsdata=pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv',dtype={'article_id': str})","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:37:30.787339Z","iopub.execute_input":"2022-04-07T14:37:30.788107Z","iopub.status.idle":"2022-04-07T14:38:08.566260Z","shell.execute_reply.started":"2022-04-07T14:37:30.788065Z","shell.execute_reply":"2022-04-07T14:38:08.565335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactionsdata","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:38:19.752183Z","iopub.execute_input":"2022-04-07T14:38:19.752437Z","iopub.status.idle":"2022-04-07T14:38:19.767786Z","shell.execute_reply.started":"2022-04-07T14:38:19.752411Z","shell.execute_reply":"2022-04-07T14:38:19.766969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=transactionsdata.drop(['t_dat', 'price','sales_channel_id'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:38:28.465285Z","iopub.execute_input":"2022-04-07T14:38:28.465584Z","iopub.status.idle":"2022-04-07T14:38:29.182731Z","shell.execute_reply.started":"2022-04-07T14:38:28.465544Z","shell.execute_reply":"2022-04-07T14:38:29.182052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:38:30.525226Z","iopub.execute_input":"2022-04-07T14:38:30.525628Z","iopub.status.idle":"2022-04-07T14:38:30.535702Z","shell.execute_reply.started":"2022-04-07T14:38:30.525598Z","shell.execute_reply":"2022-04-07T14:38:30.534843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import random","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:33:21.372134Z","iopub.execute_input":"2022-04-07T14:33:21.372448Z","iopub.status.idle":"2022-04-07T14:33:21.376967Z","shell.execute_reply.started":"2022-04-07T14:33:21.372410Z","shell.execute_reply":"2022-04-07T14:33:21.376048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_12_items = transactionsdata.groupby('article_id')['customer_id'].nunique().sort_values(ascending=False).head(12).index.tolist()\ntop_12_items","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:38:35.442199Z","iopub.execute_input":"2022-04-07T14:38:35.442473Z","iopub.status.idle":"2022-04-07T14:39:02.105920Z","shell.execute_reply.started":"2022-04-07T14:38:35.442439Z","shell.execute_reply":"2022-04-07T14:39:02.105316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss=pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:33:22.755457Z","iopub.execute_input":"2022-04-07T14:33:22.755763Z","iopub.status.idle":"2022-04-07T14:33:27.412878Z","shell.execute_reply.started":"2022-04-07T14:33:22.755723Z","shell.execute_reply":"2022-04-07T14:33:27.412080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:33:27.413896Z","iopub.execute_input":"2022-04-07T14:33:27.414104Z","iopub.status.idle":"2022-04-07T14:33:27.425225Z","shell.execute_reply.started":"2022-04-07T14:33:27.414080Z","shell.execute_reply":"2022-04-07T14:33:27.424339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss['prediction'] =  ' '.join(top_12_items)\n","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:40:16.178897Z","iopub.execute_input":"2022-04-07T14:40:16.179194Z","iopub.status.idle":"2022-04-07T14:40:16.196325Z","shell.execute_reply.started":"2022-04-07T14:40:16.179162Z","shell.execute_reply":"2022-04-07T14:40:16.195636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss.to_csv('submission.csv', index=False)\nss.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-07T14:40:21.280303Z","iopub.execute_input":"2022-04-07T14:40:21.280705Z","iopub.status.idle":"2022-04-07T14:40:28.089407Z","shell.execute_reply.started":"2022-04-07T14:40:21.280677Z","shell.execute_reply":"2022-04-07T14:40:28.088544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}