{"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":"# Recommending Top 12 Articles","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 cv2\nimport matplotlib.pyplot as plt\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-15T13:37:06.446932Z","iopub.execute_input":"2022-02-15T13:37:06.447425Z","iopub.status.idle":"2022-02-15T13:37:06.451725Z","shell.execute_reply.started":"2022-02-15T13:37:06.447384Z","shell.execute_reply":"2022-02-15T13:37:06.450772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:06.453034Z","iopub.execute_input":"2022-02-15T13:37:06.453466Z","iopub.status.idle":"2022-02-15T13:37:11.671928Z","shell.execute_reply.started":"2022-02-15T13:37:06.453419Z","shell.execute_reply":"2022-02-15T13:37:11.670391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.shape","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:11.673238Z","iopub.execute_input":"2022-02-15T13:37:11.673489Z","iopub.status.idle":"2022-02-15T13:37:11.683145Z","shell.execute_reply.started":"2022-02-15T13:37:11.673460Z","shell.execute_reply":"2022-02-15T13:37:11.681695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.head(1)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:11.685707Z","iopub.execute_input":"2022-02-15T13:37:11.685954Z","iopub.status.idle":"2022-02-15T13:37:11.716242Z","shell.execute_reply.started":"2022-02-15T13:37:11.685927Z","shell.execute_reply":"2022-02-15T13:37:11.715281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(sample_submission['prediction'][0])","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:11.717484Z","iopub.execute_input":"2022-02-15T13:37:11.717710Z","iopub.status.idle":"2022-02-15T13:37:11.727463Z","shell.execute_reply.started":"2022-02-15T13:37:11.717681Z","shell.execute_reply":"2022-02-15T13:37:11.726366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/customers.csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:11.728569Z","iopub.execute_input":"2022-02-15T13:37:11.728776Z","iopub.status.idle":"2022-02-15T13:37:17.636649Z","shell.execute_reply.started":"2022-02-15T13:37:11.728752Z","shell.execute_reply":"2022-02-15T13:37:17.635613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:17.638020Z","iopub.execute_input":"2022-02-15T13:37:17.638493Z","iopub.status.idle":"2022-02-15T13:37:17.654994Z","shell.execute_reply.started":"2022-02-15T13:37:17.638450Z","shell.execute_reply":"2022-02-15T13:37:17.654104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/articles.csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:17.656375Z","iopub.execute_input":"2022-02-15T13:37:17.656681Z","iopub.status.idle":"2022-02-15T13:37:18.711085Z","shell.execute_reply.started":"2022-02-15T13:37:17.656649Z","shell.execute_reply":"2022-02-15T13:37:18.710140Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:18.713249Z","iopub.execute_input":"2022-02-15T13:37:18.713529Z","iopub.status.idle":"2022-02-15T13:37:18.744806Z","shell.execute_reply.started":"2022-02-15T13:37:18.713495Z","shell.execute_reply":"2022-02-15T13:37:18.743848Z"},"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')","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:37:18.746539Z","iopub.execute_input":"2022-02-15T13:37:18.747255Z","iopub.status.idle":"2022-02-15T13:38:24.237914Z","shell.execute_reply.started":"2022-02-15T13:37:18.747201Z","shell.execute_reply":"2022-02-15T13:38:24.237115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:38:24.239565Z","iopub.execute_input":"2022-02-15T13:38:24.239886Z","iopub.status.idle":"2022-02-15T13:38:24.245783Z","shell.execute_reply.started":"2022-02-15T13:38:24.239782Z","shell.execute_reply":"2022-02-15T13:38:24.244576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:38:24.246790Z","iopub.execute_input":"2022-02-15T13:38:24.247013Z","iopub.status.idle":"2022-02-15T13:38:24.266901Z","shell.execute_reply.started":"2022-02-15T13:38:24.246985Z","shell.execute_reply":"2022-02-15T13:38:24.266311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_article_ids = transactions_train['article_id'].value_counts()\nbest_article_ids","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:38:24.268168Z","iopub.execute_input":"2022-02-15T13:38:24.268810Z","iopub.status.idle":"2022-02-15T13:38:25.698476Z","shell.execute_reply.started":"2022-02-15T13:38:24.268778Z","shell.execute_reply":"2022-02-15T13:38:25.697419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_article_ids.head(12)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:38:25.699792Z","iopub.execute_input":"2022-02-15T13:38:25.700113Z","iopub.status.idle":"2022-02-15T13:38:25.706517Z","shell.execute_reply.started":"2022-02-15T13:38:25.700049Z","shell.execute_reply":"2022-02-15T13:38:25.705445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top12 = ''\nfor i in range(12):\n    top12 = str(best_article_ids.index[11 - i] + 10000000000)[1:] + ' ' + top12\nprint(top12)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:38:25.707859Z","iopub.execute_input":"2022-02-15T13:38:25.708769Z","iopub.status.idle":"2022-02-15T13:38:25.720777Z","shell.execute_reply.started":"2022-02-15T13:38:25.708723Z","shell.execute_reply":"2022-02-15T13:38:25.719791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission['prediction'] = top12","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:38:25.722225Z","iopub.execute_input":"2022-02-15T13:38:25.724178Z","iopub.status.idle":"2022-02-15T13:38:25.746025Z","shell.execute_reply.started":"2022-02-15T13:38:25.724138Z","shell.execute_reply":"2022-02-15T13:38:25.745155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.to_csv('submission.csv', index = False)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:38:25.747010Z","iopub.execute_input":"2022-02-15T13:38:25.747241Z","iopub.status.idle":"2022-02-15T13:38:32.080790Z","shell.execute_reply.started":"2022-02-15T13:38:25.747213Z","shell.execute_reply":"2022-02-15T13:38:32.080080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:38:32.081893Z","iopub.execute_input":"2022-02-15T13:38:32.082457Z","iopub.status.idle":"2022-02-15T13:38:32.094731Z","shell.execute_reply.started":"2022-02-15T13:38:32.082422Z","shell.execute_reply":"2022-02-15T13:38:32.093909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Displaying pictures","metadata":{}},{"cell_type":"code","source":"dir_name = '../input/h-and-m-personalized-fashion-recommendations/images'\n\ndef show_jpg(file_name):\n    folder_name = file_name\n    file_path = dir_name + '/' + folder_name[:3]  + '/' + file_name + '.jpg'\n    if file_name + '.jpg' in os.listdir(dir_name + '/' + folder_name[:3]):       \n        img = cv2.imread(file_path)\n        plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) \n        plt.show()\n    else:\n        print('<<No Image>>')\n","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:40:02.205118Z","iopub.execute_input":"2022-02-15T13:40:02.205563Z","iopub.status.idle":"2022-02-15T13:40:02.224078Z","shell.execute_reply.started":"2022-02-15T13:40:02.205516Z","shell.execute_reply":"2022-02-15T13:40:02.223289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top12 = '0706016001 0706016002 0372860001 0610776002 0759871002 0464297007 0372860002 0610776001 0399223001 0706016003 0720125001 0156231001'\nfor i in range(12):\n    file_name = top12[11 * i:11 * i + 10]\n    folder_name = file_name\n    print(file_name + '.jpg')\n    show_jpg(file_name)\n","metadata":{"execution":{"iopub.status.busy":"2022-02-15T13:40:05.340018Z","iopub.execute_input":"2022-02-15T13:40:05.340787Z","iopub.status.idle":"2022-02-15T13:40:10.375327Z","shell.execute_reply.started":"2022-02-15T13:40:05.340750Z","shell.execute_reply":"2022-02-15T13:40:10.369797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}