{"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":"# **Introduction**","metadata":{}},{"cell_type":"markdown","source":"\n\nThe dataset contains 4 csv files and one folder with several subfolders, each with a different number of images.\n\nIn this Exploratory Data Analysis Notebook we will look to the data, will analyze the content of each csv file, check for missing data, understand the data distribution, see what are the relations between data in various files.\n\nWe will also explore the image data, understand how images are indexed in the csv files, if there are articles in the dataset without images. We will also explore image additional information, like image width and height.\n\nWe also investigate a very simple baseline model and create an initial submission.\n","metadata":{"editable":false}},{"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\nimport numpy as np  # linear algebra\nimport pandas as pd   # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\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\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\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\n","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:36:15.870455Z","iopub.execute_input":"2022-03-30T06:36:15.871002Z","iopub.status.idle":"2022-03-30T06:36:50.318529Z","shell.execute_reply.started":"2022-03-30T06:36:15.870874Z","shell.execute_reply":"2022-03-30T06:36:50.317454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Dataset**","metadata":{}},{"cell_type":"markdown","source":"**Customer Dataset Detail**","metadata":{}},{"cell_type":"code","source":"customer = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:36:50.320411Z","iopub.execute_input":"2022-03-30T06:36:50.320675Z","iopub.status.idle":"2022-03-30T06:36:53.875895Z","shell.execute_reply.started":"2022-03-30T06:36:50.320641Z","shell.execute_reply":"2022-03-30T06:36:53.874806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer.head()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:36:53.87744Z","iopub.execute_input":"2022-03-30T06:36:53.877926Z","iopub.status.idle":"2022-03-30T06:36:53.896411Z","shell.execute_reply.started":"2022-03-30T06:36:53.87789Z","shell.execute_reply":"2022-03-30T06:36:53.895747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer.shape","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:36:53.897955Z","iopub.execute_input":"2022-03-30T06:36:53.898885Z","iopub.status.idle":"2022-03-30T06:36:53.906713Z","shell.execute_reply.started":"2022-03-30T06:36:53.898837Z","shell.execute_reply":"2022-03-30T06:36:53.90577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer.columns","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:36:53.908097Z","iopub.execute_input":"2022-03-30T06:36:53.908934Z","iopub.status.idle":"2022-03-30T06:36:53.921935Z","shell.execute_reply.started":"2022-03-30T06:36:53.908898Z","shell.execute_reply":"2022-03-30T06:36:53.92123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Article Dataset Detail**","metadata":{}},{"cell_type":"code","source":"article = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:36:53.922925Z","iopub.execute_input":"2022-03-30T06:36:53.924247Z","iopub.status.idle":"2022-03-30T06:36:54.588269Z","shell.execute_reply.started":"2022-03-30T06:36:53.924031Z","shell.execute_reply":"2022-03-30T06:36:54.587557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:36:54.589585Z","iopub.execute_input":"2022-03-30T06:36:54.590419Z","iopub.status.idle":"2022-03-30T06:36:54.621508Z","shell.execute_reply.started":"2022-03-30T06:36:54.590384Z","shell.execute_reply":"2022-03-30T06:36:54.620693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:36:54.622646Z","iopub.execute_input":"2022-03-30T06:36:54.622898Z","iopub.status.idle":"2022-03-30T06:36:54.636339Z","shell.execute_reply.started":"2022-03-30T06:36:54.622867Z","shell.execute_reply":"2022-03-30T06:36:54.635277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.columns","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:36:54.638065Z","iopub.execute_input":"2022-03-30T06:36:54.638542Z","iopub.status.idle":"2022-03-30T06:36:54.64995Z","shell.execute_reply.started":"2022-03-30T06:36:54.638508Z","shell.execute_reply":"2022-03-30T06:36:54.649136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Transaction**","metadata":{}},{"cell_type":"code","source":"tran = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:36:54.653256Z","iopub.execute_input":"2022-03-30T06:36:54.653714Z","iopub.status.idle":"2022-03-30T06:37:30.214186Z","shell.execute_reply.started":"2022-03-30T06:36:54.653679Z","shell.execute_reply":"2022-03-30T06:37:30.212643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tran.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:37:30.216212Z","iopub.execute_input":"2022-03-30T06:37:30.216659Z","iopub.status.idle":"2022-03-30T06:37:30.230816Z","shell.execute_reply.started":"2022-03-30T06:37:30.216608Z","shell.execute_reply":"2022-03-30T06:37:30.229424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Info**","metadata":{}},{"cell_type":"markdown","source":"**Customer**","metadata":{}},{"cell_type":"code","source":"customer.info()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:30.232675Z","iopub.execute_input":"2022-03-30T06:37:30.233059Z","iopub.status.idle":"2022-03-30T06:37:30.787437Z","shell.execute_reply.started":"2022-03-30T06:37:30.233018Z","shell.execute_reply":"2022-03-30T06:37:30.786211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer.FN.isnull().sum()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:30.789345Z","iopub.execute_input":"2022-03-30T06:37:30.789722Z","iopub.status.idle":"2022-03-30T06:37:30.802177Z","shell.execute_reply.started":"2022-03-30T06:37:30.789658Z","shell.execute_reply":"2022-03-30T06:37:30.800725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer.isna().sum()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:30.803876Z","iopub.execute_input":"2022-03-30T06:37:30.804231Z","iopub.status.idle":"2022-03-30T06:37:31.325709Z","shell.execute_reply.started":"2022-03-30T06:37:30.804178Z","shell.execute_reply":"2022-03-30T06:37:31.324658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer.duplicated().values.sum()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:31.326963Z","iopub.execute_input":"2022-03-30T06:37:31.327229Z","iopub.status.idle":"2022-03-30T06:37:33.036691Z","shell.execute_reply.started":"2022-03-30T06:37:31.327193Z","shell.execute_reply":"2022-03-30T06:37:33.035728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer.describe().T","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:33.037825Z","iopub.execute_input":"2022-03-30T06:37:33.03805Z","iopub.status.idle":"2022-03-30T06:37:33.221678Z","shell.execute_reply.started":"2022-03-30T06:37:33.03802Z","shell.execute_reply":"2022-03-30T06:37:33.220707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"The dataframe customers has {len(customer)} rows\")","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:33.223313Z","iopub.execute_input":"2022-03-30T06:37:33.223588Z","iopub.status.idle":"2022-03-30T06:37:33.22969Z","shell.execute_reply.started":"2022-03-30T06:37:33.223552Z","shell.execute_reply":"2022-03-30T06:37:33.228723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Article**","metadata":{}},{"cell_type":"code","source":"article.info()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:33.230915Z","iopub.execute_input":"2022-03-30T06:37:33.231163Z","iopub.status.idle":"2022-03-30T06:37:33.386545Z","shell.execute_reply.started":"2022-03-30T06:37:33.231125Z","shell.execute_reply":"2022-03-30T06:37:33.385555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.describe()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:33.387932Z","iopub.execute_input":"2022-03-30T06:37:33.388364Z","iopub.status.idle":"2022-03-30T06:37:33.461183Z","shell.execute_reply.started":"2022-03-30T06:37:33.388308Z","shell.execute_reply":"2022-03-30T06:37:33.460423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.isnull().sum()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:33.462932Z","iopub.execute_input":"2022-03-30T06:37:33.463508Z","iopub.status.idle":"2022-03-30T06:37:33.607426Z","shell.execute_reply.started":"2022-03-30T06:37:33.46346Z","shell.execute_reply":"2022-03-30T06:37:33.606381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.isnull().values.sum()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:33.608907Z","iopub.execute_input":"2022-03-30T06:37:33.609901Z","iopub.status.idle":"2022-03-30T06:37:33.764865Z","shell.execute_reply.started":"2022-03-30T06:37:33.609852Z","shell.execute_reply":"2022-03-30T06:37:33.763809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.prod_name.unique()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:33.766716Z","iopub.execute_input":"2022-03-30T06:37:33.767085Z","iopub.status.idle":"2022-03-30T06:37:33.789956Z","shell.execute_reply.started":"2022-03-30T06:37:33.767034Z","shell.execute_reply":"2022-03-30T06:37:33.788826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"The dataframe artical has {len(article)} rows\")","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:33.791513Z","iopub.execute_input":"2022-03-30T06:37:33.792187Z","iopub.status.idle":"2022-03-30T06:37:33.798168Z","shell.execute_reply.started":"2022-03-30T06:37:33.792136Z","shell.execute_reply":"2022-03-30T06:37:33.797104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Transactions**","metadata":{}},{"cell_type":"code","source":"tran.sales_channel_id.unique()","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:37:33.799451Z","iopub.execute_input":"2022-03-30T06:37:33.799706Z","iopub.status.idle":"2022-03-30T06:37:34.006464Z","shell.execute_reply.started":"2022-03-30T06:37:33.799674Z","shell.execute_reply":"2022-03-30T06:37:34.005366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **EDA**","metadata":{}},{"cell_type":"code","source":"# import seaborn\nimport seaborn as sns\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:34.007672Z","iopub.execute_input":"2022-03-30T06:37:34.008034Z","iopub.status.idle":"2022-03-30T06:37:34.444239Z","shell.execute_reply.started":"2022-03-30T06:37:34.007983Z","shell.execute_reply":"2022-03-30T06:37:34.443226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (16,8))\nplt.title(\"Histogram of data in Activity Dataframe\")\nsns.countplot(hue = 'index_code', x='department_name',data = article);\nplt.show()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:34.446065Z","iopub.execute_input":"2022-03-30T06:37:34.446794Z","iopub.status.idle":"2022-03-30T06:37:48.40065Z","shell.execute_reply.started":"2022-03-30T06:37:34.446742Z","shell.execute_reply":"2022-03-30T06:37:48.399601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10, 5))\nax = sns.histplot(data=article, y='index_name', color='green')\nax.set_xlabel('count by index name')\nax.set_ylabel('index name')\nplt.show()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:48.402378Z","iopub.execute_input":"2022-03-30T06:37:48.402762Z","iopub.status.idle":"2022-03-30T06:37:48.823991Z","shell.execute_reply.started":"2022-03-30T06:37:48.402711Z","shell.execute_reply":"2022-03-30T06:37:48.82302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10, 5))\nax = sns.histplot(data=article, y='garment_group_name', color='orange', hue='index_group_name', multiple=\"stack\")\nax.set_xlabel('count by garment group')\nax.set_ylabel('garment group')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:46:52.98534Z","iopub.execute_input":"2022-03-30T06:46:52.985878Z","iopub.status.idle":"2022-03-30T06:46:54.177402Z","shell.execute_reply.started":"2022-03-30T06:46:52.985825Z","shell.execute_reply":"2022-03-30T06:46:54.176373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customer, x='age', bins=50, color='blue')\nax.set_xlabel('Distribution of the customers age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:50:41.539061Z","iopub.execute_input":"2022-03-30T06:50:41.539386Z","iopub.status.idle":"2022-03-30T06:50:42.262536Z","shell.execute_reply.started":"2022-03-30T06:50:41.539353Z","shell.execute_reply":"2022-03-30T06:50:42.260789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customer, x='club_member_status', color='Red')\nax.set_xlabel('Distribution of club member status')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:51:17.368571Z","iopub.execute_input":"2022-03-30T06:51:17.368892Z","iopub.status.idle":"2022-03-30T06:51:19.336371Z","shell.execute_reply.started":"2022-03-30T06:51:17.368854Z","shell.execute_reply":"2022-03-30T06:51:19.335309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tran.describe()['price']","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:52:28.973564Z","iopub.execute_input":"2022-03-30T06:52:28.973885Z","iopub.status.idle":"2022-03-30T06:52:31.923682Z","shell.execute_reply.started":"2022-03-30T06:52:28.973848Z","shell.execute_reply":"2022-03-30T06:52:31.922668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid')\nf, ax = plt.subplots(figsize=(10,5))\nax = sns.boxplot(data=tran, x='price', color='orange')\nax.set_xlabel('Price outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-30T06:53:36.003869Z","iopub.execute_input":"2022-03-30T06:53:36.004861Z","iopub.status.idle":"2022-03-30T06:53:40.506006Z","shell.execute_reply.started":"2022-03-30T06:53:36.004797Z","shell.execute_reply":"2022-03-30T06:53:40.505349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"price_more_than_two = tran[tran[\"price\"]>0.20]\nprint(price_more_than_two.head())","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:48.827498Z","iopub.execute_input":"2022-03-30T06:37:48.827738Z","iopub.status.idle":"2022-03-30T06:37:48.960812Z","shell.execute_reply.started":"2022-03-30T06:37:48.827707Z","shell.execute_reply":"2022-03-30T06:37:48.96006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cp = tran[[\"t_dat\",\"price\"]]\ncp.head()","metadata":{"editable":false,"execution":{"iopub.status.busy":"2022-03-30T06:37:48.962185Z","iopub.execute_input":"2022-03-30T06:37:48.962731Z","iopub.status.idle":"2022-03-30T06:37:49.32582Z","shell.execute_reply.started":"2022-03-30T06:37:48.962696Z","shell.execute_reply":"2022-03-30T06:37:49.324639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"editable":false},"execution_count":null,"outputs":[]}]}