{"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":"# Caution: This notebook (dtale) doesn't work in Kaggle notebook.\n- You should download this notebook and run locally.","metadata":{}},{"cell_type":"code","source":"!pip install dtale","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:33:20.996114Z","iopub.execute_input":"2022-03-19T04:33:20.996398Z","iopub.status.idle":"2022-03-19T04:33:53.286868Z","shell.execute_reply.started":"2022-03-19T04:33:20.996362Z","shell.execute_reply":"2022-03-19T04:33:53.285981Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport dtale\n\n# If you run this code in Google Colab, uncomment the following two lines\n# import dtale.app as dtale_app\n# dtale_app.USE_COLAB = True\n\ninput_dir = '../input/h-and-m-personalized-fashion-recommendations'","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:34:09.464241Z","iopub.execute_input":"2022-03-19T04:34:09.464914Z","iopub.status.idle":"2022-03-19T04:34:09.468527Z","shell.execute_reply.started":"2022-03-19T04:34:09.464887Z","shell.execute_reply":"2022-03-19T04:34:09.467656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv(f'{input_dir}/articles.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:34:10.498205Z","iopub.execute_input":"2022-03-19T04:34:10.498444Z","iopub.status.idle":"2022-03-19T04:34:11.486773Z","shell.execute_reply.started":"2022-03-19T04:34:10.498420Z","shell.execute_reply":"2022-03-19T04:34:11.486046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# You can do EDA if you run this code locally\ndtale.show(articles)","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:36:24.132206Z","iopub.execute_input":"2022-03-19T04:36:24.133136Z","iopub.status.idle":"2022-03-19T04:36:24.151118Z","shell.execute_reply.started":"2022-03-19T04:36:24.133077Z","shell.execute_reply":"2022-03-19T04:36:24.150462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers = pd.read_csv(f'{input_dir}/customers.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:46:06.922865Z","iopub.execute_input":"2022-03-19T04:46:06.923101Z","iopub.status.idle":"2022-03-19T04:46:12.442224Z","shell.execute_reply.started":"2022-03-19T04:46:06.923075Z","shell.execute_reply":"2022-03-19T04:46:12.441561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sampling (because of too large data)\ncustomers = customers.sample(frac=0.01)","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:46:14.751728Z","iopub.execute_input":"2022-03-19T04:46:14.752180Z","iopub.status.idle":"2022-03-19T04:46:14.869585Z","shell.execute_reply.started":"2022-03-19T04:46:14.752153Z","shell.execute_reply":"2022-03-19T04:46:14.868903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# You can do EDA if you run this code locally\ndtale.show(customers)\n\n# FN is if a customer get Fashion News newsletter, \n# Active is if the customer is active for communication, sales channel id, 2 is online and 1 store.","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:48:56.399527Z","iopub.execute_input":"2022-03-19T04:48:56.399792Z","iopub.status.idle":"2022-03-19T04:48:56.517991Z","shell.execute_reply.started":"2022-03-19T04:48:56.399762Z","shell.execute_reply":"2022-03-19T04:48:56.516710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions = pd.read_csv(f'{input_dir}/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:49:01.091392Z","iopub.execute_input":"2022-03-19T04:49:01.091638Z","iopub.status.idle":"2022-03-19T04:50:06.534098Z","shell.execute_reply.started":"2022-03-19T04:49:01.091610Z","shell.execute_reply":"2022-03-19T04:50:06.533422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sampling (because of too large data)\ntransactions = transactions.sample(frac=0.001)","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:50:07.027423Z","iopub.execute_input":"2022-03-19T04:50:07.027976Z","iopub.status.idle":"2022-03-19T04:50:12.830981Z","shell.execute_reply.started":"2022-03-19T04:50:07.027950Z","shell.execute_reply":"2022-03-19T04:50:12.830121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# You can do EDA if you run this code locally\ndtale.show(transactions)","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:50:24.770217Z","iopub.execute_input":"2022-03-19T04:50:24.771991Z","iopub.status.idle":"2022-03-19T04:50:24.959283Z","shell.execute_reply.started":"2022-03-19T04:50:24.771956Z","shell.execute_reply":"2022-03-19T04:50:24.958263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Check image data","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:50:51.339627Z","iopub.execute_input":"2022-03-19T04:50:51.340856Z","iopub.status.idle":"2022-03-19T04:50:51.380406Z","shell.execute_reply.started":"2022-03-19T04:50:51.340809Z","shell.execute_reply":"2022-03-19T04:50:51.379830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def check_img(article_ids):\n    len_articles = len(article_ids)-1\n    f, ax = plt.subplots(len_articles//5+1, 5, figsize=(20,10))\n    i = 0\n    plt.subplots_adjust(wspace=0.4, hspace=0.6)\n    for article_id in article_ids:\n        desc = articles[articles['article_id'] == article_id]['detail_desc'].iloc[0]\n        desc_list = desc.split(' ')\n        for j, elem in enumerate(desc_list):\n            if j > 0 and j % 5 == 0:\n                desc_list[j] = desc_list[j] + '\\n'\n        desc = ' '.join(desc_list)\n        img = mpimg.imread(f'{input_dir}/images/0{str(article_id)[:2]}/0{int(article_id)}.jpg')\n        if len_articles//5+1 == 1:\n            ax[i].imshow(img)\n            ax[i].set_title(article_id)\n            ax[i].set_xticks([], [])\n            ax[i].set_yticks([], [])\n            ax[i].grid(False)\n            ax[i].set_xlabel(desc, fontsize=10)\n            i += 1\n        elif len_articles//5+1 > 1:\n            ax[i//5, i-(i//5)*5].imshow(img)\n            ax[i//5, i-(i//5)*5].set_title(article_id)\n            ax[i//5, i-(i//5)*5].set_xticks([], [])\n            ax[i//5, i-(i//5)*5].set_yticks([], [])\n            ax[i//5, i-(i//5)*5].grid(False)\n            ax[i//5, i-(i//5)*5].set_xlabel(desc, fontsize=10)\n            i += 1\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-19T04:50:57.133030Z","iopub.execute_input":"2022-03-19T04:50:57.133257Z","iopub.status.idle":"2022-03-19T04:50:57.145560Z","shell.execute_reply.started":"2022-03-19T04:50:57.133233Z","shell.execute_reply":"2022-03-19T04:50:57.144332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.tail(n=5)","metadata":{"execution":{"iopub.status.busy":"2022-03-19T05:03:57.617736Z","iopub.execute_input":"2022-03-19T05:03:57.618305Z","iopub.status.idle":"2022-03-19T05:03:57.640635Z","shell.execute_reply.started":"2022-03-19T05:03:57.618278Z","shell.execute_reply":"2022-03-19T05:03:57.639314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check_img([953450001, 953763001, 956217002, 957375001, 959461001])","metadata":{"execution":{"iopub.status.busy":"2022-03-19T05:04:22.368791Z","iopub.execute_input":"2022-03-19T05:04:22.369042Z","iopub.status.idle":"2022-03-19T05:04:24.138493Z","shell.execute_reply.started":"2022-03-19T05:04:22.369018Z","shell.execute_reply":"2022-03-19T05:04:24.137546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}