{"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 # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport matplotlib as mpl\nfrom cycler import cycler\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:19:43.281263Z","iopub.execute_input":"2022-05-19T18:19:43.281864Z","iopub.status.idle":"2022-05-19T18:19:44.450757Z","shell.execute_reply.started":"2022-05-19T18:19:43.281772Z","shell.execute_reply":"2022-05-19T18:19:44.449784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_articles = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ndf_tran = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")\ndf_cust = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:19:44.452502Z","iopub.execute_input":"2022-05-19T18:19:44.453358Z","iopub.status.idle":"2022-05-19T18:20:59.511046Z","shell.execute_reply.started":"2022-05-19T18:19:44.453312Z","shell.execute_reply":"2022-05-19T18:20:59.510047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analysis of articles","metadata":{}},{"cell_type":"code","source":"for i in df_articles.columns:\n    print(i,len(df_articles[i].unique()) )","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:20:59.512267Z","iopub.execute_input":"2022-05-19T18:20:59.512494Z","iopub.status.idle":"2022-05-19T18:20:59.687846Z","shell.execute_reply.started":"2022-05-19T18:20:59.512468Z","shell.execute_reply":"2022-05-19T18:20:59.686889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Number of articles of each index_name","metadata":{}},{"cell_type":"code","source":"print(f\"Figure figsize: {plt.rcParams.get('figure.figsize')}\")\nprint(f\"Figure dpi: {plt.rcParams.get('figure.dpi')}\")\nprint(f\"Savefig dpi: {plt.rcParams.get('savefig.dpi')}\\n\")\n\nprint(f\"Font size: {plt.rcParams.get('font.size')}\")\nprint(f\"Legend fontsize: {plt.rcParams.get('legend.fontsize')}\")\nprint(f\"Figure titlesize: {plt.rcParams.get('figure.titlesize')}\\n\")\n\nprint(f\"Axes prop_cycle: {plt.rcParams.get('axes.prop_cycle')}\\n\")","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:20:59.690263Z","iopub.execute_input":"2022-05-19T18:20:59.690776Z","iopub.status.idle":"2022-05-19T18:20:59.698837Z","shell.execute_reply.started":"2022-05-19T18:20:59.690724Z","shell.execute_reply":"2022-05-19T18:20:59.697876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"n = 10\ncolor = plt.cm.coolwarm(np.linspace(0, 2, n))\n\nprint(color)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:20:59.700561Z","iopub.execute_input":"2022-05-19T18:20:59.701473Z","iopub.status.idle":"2022-05-19T18:20:59.713822Z","shell.execute_reply.started":"2022-05-19T18:20:59.701423Z","shell.execute_reply":"2022-05-19T18:20:59.712484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rcParams['figure.figsize'] = [16.0, 10.0]\nmpl.rcParams['figure.dpi'] = 80\nmpl.rcParams['savefig.dpi'] = 100\n\nmpl.rcParams['font.size'] = 14\nmpl.rcParams['legend.fontsize'] = 'xx-large'\nmpl.rcParams['figure.titlesize'] = 'x-large'\n\nmpl.rcParams['axes.prop_cycle'] = cycler('color', color)\n\nprint(plt.rcParams.get('figure.figsize'))\nprint(plt.rcParams.get('figure.dpi'))\nprint(plt.rcParams.get('savefig.dpi'))\n\nprint(plt.rcParams.get('font.size'))\nprint(plt.rcParams.get('legend.fontsize'))\nprint(plt.rcParams.get('figure.titlesize'))\n\nprint(plt.rcParams.get('axes.prop_cycle'))","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:20:59.715614Z","iopub.execute_input":"2022-05-19T18:20:59.716260Z","iopub.status.idle":"2022-05-19T18:20:59.729242Z","shell.execute_reply.started":"2022-05-19T18:20:59.716191Z","shell.execute_reply":"2022-05-19T18:20:59.728098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_theme(style=\"darkgrid\")\nax = sns.countplot(x=\"index_group_name\", data = df_articles)\na = plt.xticks(rotation=45)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:20:59.730516Z","iopub.execute_input":"2022-05-19T18:20:59.730860Z","iopub.status.idle":"2022-05-19T18:21:00.179796Z","shell.execute_reply.started":"2022-05-19T18:20:59.730830Z","shell.execute_reply":"2022-05-19T18:21:00.178873Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Number of articles of each product type","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(x=\"product_type_name\", data = df_articles, palette=\"Set1\")\na = plt.xticks(rotation=90, fontsize=10)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:00.181136Z","iopub.execute_input":"2022-05-19T18:21:00.181644Z","iopub.status.idle":"2022-05-19T18:21:04.848092Z","shell.execute_reply.started":"2022-05-19T18:21:00.181600Z","shell.execute_reply":"2022-05-19T18:21:04.847161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Number of articles of each graphical appearance name","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(x=\"graphical_appearance_name\", data = df_articles, palette=\"Set2\")\na = plt.xticks(rotation=90)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:04.849428Z","iopub.execute_input":"2022-05-19T18:21:04.849658Z","iopub.status.idle":"2022-05-19T18:21:05.505478Z","shell.execute_reply.started":"2022-05-19T18:21:04.849630Z","shell.execute_reply":"2022-05-19T18:21:05.504457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Number of articles of each colour","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(x=\"colour_group_name\", data = df_articles, palette=\"Set3\")\na = plt.xticks(rotation=90)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:05.508123Z","iopub.execute_input":"2022-05-19T18:21:05.508432Z","iopub.status.idle":"2022-05-19T18:21:07.580725Z","shell.execute_reply.started":"2022-05-19T18:21:05.508397Z","shell.execute_reply":"2022-05-19T18:21:07.580129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analysis of customer","metadata":{}},{"cell_type":"code","source":"for i in df_cust.columns:\n    print(i,len(df_cust[i].unique()) )","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:07.581726Z","iopub.execute_input":"2022-05-19T18:21:07.582412Z","iopub.status.idle":"2022-05-19T18:21:09.044962Z","shell.execute_reply.started":"2022-05-19T18:21:07.582376Z","shell.execute_reply":"2022-05-19T18:21:09.043977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cust.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:09.046249Z","iopub.execute_input":"2022-05-19T18:21:09.046559Z","iopub.status.idle":"2022-05-19T18:21:09.669289Z","shell.execute_reply.started":"2022-05-19T18:21:09.046516Z","shell.execute_reply":"2022-05-19T18:21:09.668261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cust['FN'] = df_cust['FN'].fillna(0)\ndf_cust['Active'] = df_cust['Active'].fillna(0)\ndf_cust['age'] = df_cust['age'].fillna(0)\ndf_cust['club_member_status'] = df_cust['club_member_status'].fillna(\"No info\")\ndf_cust['fashion_news_frequency'] = df_cust['fashion_news_frequency'].fillna(\"None\")\ndf_cust['fashion_news_frequency'] = df_cust['fashion_news_frequency'].replace(\"NONE\", \"None\")","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:09.670702Z","iopub.execute_input":"2022-05-19T18:21:09.670939Z","iopub.status.idle":"2022-05-19T18:21:10.203338Z","shell.execute_reply.started":"2022-05-19T18:21:09.670912Z","shell.execute_reply":"2022-05-19T18:21:10.202291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analysis of club member status","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(x=\"club_member_status\", data = df_cust, palette=\"Set3\")\na = plt.xticks(rotation=45)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:10.204488Z","iopub.execute_input":"2022-05-19T18:21:10.204738Z","iopub.status.idle":"2022-05-19T18:21:12.030319Z","shell.execute_reply.started":"2022-05-19T18:21:10.204706Z","shell.execute_reply":"2022-05-19T18:21:12.029585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analysis of fashion news frequency","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(x=\"fashion_news_frequency\", data = df_cust, palette=\"Set3\")\na = plt.xticks(rotation=45)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:12.031425Z","iopub.execute_input":"2022-05-19T18:21:12.031755Z","iopub.status.idle":"2022-05-19T18:21:13.817552Z","shell.execute_reply.started":"2022-05-19T18:21:12.031727Z","shell.execute_reply":"2022-05-19T18:21:13.816918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analysis of age","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(x=\"age\", data = df_cust, palette=\"Set3\")\na = plt.xticks(rotation=90, fontsize=12)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:13.818611Z","iopub.execute_input":"2022-05-19T18:21:13.818928Z","iopub.status.idle":"2022-05-19T18:21:16.459362Z","shell.execute_reply.started":"2022-05-19T18:21:13.818900Z","shell.execute_reply":"2022-05-19T18:21:16.458613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Analysis of transaction\n\n## Number of unique values each column has:","metadata":{}},{"cell_type":"code","source":"for i in df_tran.columns:\n    print(i,len(df_tran[i].unique()) )","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:16.460491Z","iopub.execute_input":"2022-05-19T18:21:16.460858Z","iopub.status.idle":"2022-05-19T18:21:28.107446Z","shell.execute_reply.started":"2022-05-19T18:21:16.460826Z","shell.execute_reply":"2022-05-19T18:21:28.106490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analysis of sales each month","metadata":{}},{"cell_type":"code","source":"df_tran[\"Month_year\"] = pd.to_datetime(df_tran.t_dat).dt.to_period('M')\nax = sns.countplot(x=\"Month_year\", data = df_tran, palette=\"Set3\")\na = plt.xticks(rotation=90)","metadata":{"execution":{"iopub.status.busy":"2022-05-19T18:21:28.108857Z","iopub.execute_input":"2022-05-19T18:21:28.109279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analysis of sales channel id","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(x=\"sales_channel_id\", data = df_tran, palette=\"Set3\")\na = plt.xticks(rotation=45)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = sns.stripplot(x=\"Month_year\", y = \"price\", data = df_tran, palette=\"Set3\")\na = plt.xticks(rotation=90)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tran_arti = pd.merge(\n    df_tran, \n    df_articles[[\"article_id\", \"index_group_name\", \"product_type_name\", \"graphical_appearance_name\", \"colour_group_name\"]], \n    how = \"left\", \n    on = \"article_id\"\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tran_arti.columns","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Checking sales of product types","metadata":{}},{"cell_type":"code","source":"ax = sns.countplot(x=\"product_type_name\", data = df_tran_arti, palette=\"Set3\")\na = plt.xticks(rotation=90,fontsize=10)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tran_arti.t_dat = pd.to_datetime(df_tran_arti.t_dat)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = df_tran_arti.loc[((df_tran_arti[\"t_dat\"] > \"2018-09-15\") & (df_tran_arti[\"t_dat\"] < \"2018-10-01\")) |\n                    ((df_tran_arti[\"t_dat\"] > \"2019-09-15\") & (df_tran_arti[\"t_dat\"] < \"2019-10-01\")) |\n                    ((df_tran_arti[\"t_dat\"] > \"2020-09-15\") & (df_tran_arti[\"t_dat\"] < \"2020-10-01\"))]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = sns.countplot(x=\"product_type_name\", data = a, palette=\"Set3\")\na = plt.xticks(rotation=90, fontsize=10)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}