{"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":"import numpy as np \nimport pandas as pd \n\narticles = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ncustomers = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\nsample = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/sample_submission.csv\")\ntrain = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-20T05:47:22.270958Z","iopub.execute_input":"2022-03-20T05:47:22.271508Z","iopub.status.idle":"2022-03-20T05:48:39.688615Z","shell.execute_reply.started":"2022-03-20T05:47:22.271374Z","shell.execute_reply":"2022-03-20T05:48:39.687791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**<Data Explanation>**\n \n* articles.csv - detailed metadata for each article_id available for purchase\n* customers.csv - metadata for each customer_id in dataset\n* sample_submission.csv - a sample submission file in the correct format\n* transactions_train.csv - the training data, consisting of the purchases each customer for each date, as well as additional information. Duplicate rows correspond to multiple purchases of the same item. \n* Your task is to predict the article_ids each customer will purchase during the 7-day period immediately after the training data period.\n*     \nNOTE: You must make predictions for all customer_id values found in the sample submission. All customers who made purchases during the test period are scored, regardless of whether they had purchase history in the training data.","metadata":{}},{"cell_type":"code","source":"train.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:39.690254Z","iopub.execute_input":"2022-03-20T05:48:39.690503Z","iopub.status.idle":"2022-03-20T05:48:39.712548Z","shell.execute_reply.started":"2022-03-20T05:48:39.690469Z","shell.execute_reply":"2022-03-20T05:48:39.711693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:39.713745Z","iopub.execute_input":"2022-03-20T05:48:39.71404Z","iopub.status.idle":"2022-03-20T05:48:39.757304Z","shell.execute_reply.started":"2022-03-20T05:48:39.714008Z","shell.execute_reply":"2022-03-20T05:48:39.756459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:39.758657Z","iopub.execute_input":"2022-03-20T05:48:39.759062Z","iopub.status.idle":"2022-03-20T05:48:39.773612Z","shell.execute_reply.started":"2022-03-20T05:48:39.759018Z","shell.execute_reply":"2022-03-20T05:48:39.772973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:39.775844Z","iopub.execute_input":"2022-03-20T05:48:39.776298Z","iopub.status.idle":"2022-03-20T05:48:39.800279Z","shell.execute_reply.started":"2022-03-20T05:48:39.776263Z","shell.execute_reply":"2022-03-20T05:48:39.79945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:39.801613Z","iopub.execute_input":"2022-03-20T05:48:39.802138Z","iopub.status.idle":"2022-03-20T05:48:39.981773Z","shell.execute_reply.started":"2022-03-20T05:48:39.802097Z","shell.execute_reply":"2022-03-20T05:48:39.980752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:39.982963Z","iopub.execute_input":"2022-03-20T05:48:39.983271Z","iopub.status.idle":"2022-03-20T05:48:40.601164Z","shell.execute_reply.started":"2022-03-20T05:48:39.98323Z","shell.execute_reply":"2022-03-20T05:48:40.60008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"It is complicated dataset, so let's begin with investigating meta data\n1. Articles\n2. Customers","metadata":{}},{"cell_type":"code","source":"articles[\"detail_desc\"].isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:40.602329Z","iopub.execute_input":"2022-03-20T05:48:40.602562Z","iopub.status.idle":"2022-03-20T05:48:40.62164Z","shell.execute_reply.started":"2022-03-20T05:48:40.602531Z","shell.execute_reply":"2022-03-20T05:48:40.620867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles[articles[\"detail_desc\"].isna()]","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:40.623077Z","iopub.execute_input":"2022-03-20T05:48:40.623424Z","iopub.status.idle":"2022-03-20T05:48:40.675984Z","shell.execute_reply.started":"2022-03-20T05:48:40.623378Z","shell.execute_reply":"2022-03-20T05:48:40.675331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:40.677521Z","iopub.execute_input":"2022-03-20T05:48:40.677872Z","iopub.status.idle":"2022-03-20T05:48:40.749624Z","shell.execute_reply.started":"2022-03-20T05:48:40.677829Z","shell.execute_reply":"2022-03-20T05:48:40.748757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#We can notice similarity between article_id and product_code. And from the numbers of values, it indicates that there are certian main categories of the product\narticles['product_code'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:40.750723Z","iopub.execute_input":"2022-03-20T05:48:40.751483Z","iopub.status.idle":"2022-03-20T05:48:40.763913Z","shell.execute_reply.started":"2022-03-20T05:48:40.751451Z","shell.execute_reply":"2022-03-20T05:48:40.763032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"main_prod_df = articles.groupby( ['product_code','product_type_no','product_type_name','prod_name'] ).size().to_frame(name = 'count').reset_index()\nmain_prod_df.sort_values(['count'],ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:40.765459Z","iopub.execute_input":"2022-03-20T05:48:40.765821Z","iopub.status.idle":"2022-03-20T05:48:40.914694Z","shell.execute_reply.started":"2022-03-20T05:48:40.765785Z","shell.execute_reply":"2022-03-20T05:48:40.913866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"main_prod_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:40.916221Z","iopub.execute_input":"2022-03-20T05:48:40.916702Z","iopub.status.idle":"2022-03-20T05:48:40.943301Z","shell.execute_reply.started":"2022-03-20T05:48:40.916635Z","shell.execute_reply":"2022-03-20T05:48:40.942402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n\nplt.figure(figsize=(12,4))\nplt.title('Number of articles: Product code')\nplt.xlabel('Product code Range')\nplt.ticklabel_format(axis = 'x',style ='plain')\nsns.lineplot(data =main_prod_df,x= 'product_code',y='count')\n# It seems like Product Code range between 400000 and 800000 has lots of kinds of article.","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:48:40.94633Z","iopub.execute_input":"2022-03-20T05:48:40.947024Z","iopub.status.idle":"2022-03-20T05:49:57.274854Z","shell.execute_reply.started":"2022-03-20T05:48:40.946984Z","shell.execute_reply":"2022-03-20T05:49:57.27393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles[(articles['product_code']>=600000)&(articles['product_code']<800000)].sample(10).sort_values(by='product_type_no')\n#It may not be accurate, but we can assume that product code with lots of kinds of article would be one of the common kinds of clothes type.","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:49:57.276285Z","iopub.execute_input":"2022-03-20T05:49:57.277166Z","iopub.status.idle":"2022-03-20T05:49:57.320313Z","shell.execute_reply.started":"2022-03-20T05:49:57.277119Z","shell.execute_reply":"2022-03-20T05:49:57.31948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.pivot_table(articles,index =['product_group_name','product_type_name','product_type_no'],values = ['article_id'],aggfunc =['count','min','max'])                     \n#This analysis indicates that there are certain product_type_no depending on product_group_name and product_type_name feature which means that we can discover what kind of product it is only by product_type_no!\n#Also, the range of article_id varies regardless of product type. ","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:49:57.32161Z","iopub.execute_input":"2022-03-20T05:49:57.322443Z","iopub.status.idle":"2022-03-20T05:49:57.444773Z","shell.execute_reply.started":"2022-03-20T05:49:57.322398Z","shell.execute_reply":"2022-03-20T05:49:57.443964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-03-20T05:49:57.446026Z","iopub.execute_input":"2022-03-20T05:49:57.446269Z","iopub.status.idle":"2022-03-20T05:49:57.45021Z","shell.execute_reply.started":"2022-03-20T05:49:57.44624Z","shell.execute_reply":"2022-03-20T05:49:57.449445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**To be Continued....**","metadata":{}}]}