{"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":"<a id=contents></a>\n# Contents\n\n[Articles](#articles)\n* [Unique values of each column](#unique_values_articles)\n* [prod_name](#prod_name)\n* [product_type_name](#product_type_name)\n* [product_group_name](#product_group_name)\n* [graphical_appearance_name](#graphical_appearance_name)\n* [colour_group_name](#colour_group_name)\n* [perceived_colour_value_name](#perceived_colour_value_name)\n* [perceived_colour_master_name](#perceived_colour_master_name)\n* [department_name](#department_name)\n* [index_name](#index_name)\n* [index_group_name](#index_group_name)\n* [section_name](#section_name)\n* [garment_group_name](#garment_group_name)\n\n[Customers](#customers)\n* [Unique values of each column](#unique_values_customers)\n* [FN](#FN)\n* [Active](#Active)\n* [club_member_status](#club_member_status)\n* [fashion_news_frequency](#fashion_news_frequency)\n* [age](#age)\n* [postal_code](#postal_code)\n\n[Transactions](#transactions)\n* [t_dat](#t_dat)\n* [sales_channel_id](#sales_channel_id)\n* [price](#price)\n\n[Price Distribution](#price_distribution)<br>\n[Top Selling Articles](#top_selling_articles)<br>\n[Top 10 Customers](#top_customers)<br>\n[Price Outliers By Category](#price_outliers)<br>\n[Top Selling Product Group](#top_selling_product_group)<br>\n[Sales Distribution](#sales_distribution)<br>\n[Changes in sales volume due to price changes](#sales_volume_change)<br>\n","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nfrom matplotlib import pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:26:57.701791Z","iopub.execute_input":"2022-03-18T03:26:57.702214Z","iopub.status.idle":"2022-03-18T03:26:58.880766Z","shell.execute_reply.started":"2022-03-18T03:26:57.702099Z","shell.execute_reply":"2022-03-18T03:26:58.879906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')\ncustomers = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')\ntransactions_train = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:26:58.881875Z","iopub.execute_input":"2022-03-18T03:26:58.882102Z","iopub.status.idle":"2022-03-18T03:28:14.085126Z","shell.execute_reply.started":"2022-03-18T03:26:58.882075Z","shell.execute_reply":"2022-03-18T03:28:14.083919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"articles\"></a>\n# Articles","metadata":{}},{"cell_type":"code","source":"pd.options.display.max_columns = None\narticles.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:14.086279Z","iopub.execute_input":"2022-03-18T03:28:14.086515Z","iopub.status.idle":"2022-03-18T03:28:14.121256Z","shell.execute_reply.started":"2022-03-18T03:28:14.086488Z","shell.execute_reply":"2022-03-18T03:28:14.120365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:14.123706Z","iopub.execute_input":"2022-03-18T03:28:14.124566Z","iopub.status.idle":"2022-03-18T03:28:14.312639Z","shell.execute_reply.started":"2022-03-18T03:28:14.124527Z","shell.execute_reply":"2022-03-18T03:28:14.311675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# number of unique values in each column\narticles.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:14.327797Z","iopub.execute_input":"2022-03-18T03:28:14.328129Z","iopub.status.idle":"2022-03-18T03:28:14.510784Z","shell.execute_reply.started":"2022-03-18T03:28:14.328097Z","shell.execute_reply":"2022-03-18T03:28:14.510075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"unique_values_articles\"></a>\n### Unique values of each column","metadata":{}},{"cell_type":"code","source":"# print unique values of each column\nfor c in articles.columns:\n    print(\"{} ({}) => {}\".format(c, articles[c].nunique(), articles[c].unique()))","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:14.512161Z","iopub.execute_input":"2022-03-18T03:28:14.513074Z","iopub.status.idle":"2022-03-18T03:28:14.847564Z","shell.execute_reply.started":"2022-03-18T03:28:14.513019Z","shell.execute_reply":"2022-03-18T03:28:14.846503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for c in articles.columns:\n    if articles[c].nunique() < 30 and type(articles[c].iloc[0]) is str:\n        print(\"{} ({}) => {}\".format(c, articles[c].nunique(), articles[c].unique()))","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:14.849396Z","iopub.execute_input":"2022-03-18T03:28:14.849745Z","iopub.status.idle":"2022-03-18T03:28:15.149665Z","shell.execute_reply.started":"2022-03-18T03:28:14.849673Z","shell.execute_reply":"2022-03-18T03:28:15.148835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### prod_name","metadata":{}},{"cell_type":"code","source":"# prod_name\nprint(articles['prod_name'].nunique())\nprod_name_top = articles.groupby(['prod_name']).count()['article_id'].sort_values(ascending=False).head(20)\nprod_name_top","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:15.150680Z","iopub.execute_input":"2022-03-18T03:28:15.151150Z","iopub.status.idle":"2022-03-18T03:28:15.463346Z","shell.execute_reply.started":"2022-03-18T03:28:15.151110Z","shell.execute_reply":"2022-03-18T03:28:15.462301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### product_type_name","metadata":{}},{"cell_type":"code","source":"# product_type_name\npd.options.display.max_rows = None\nprint(\"unique count : \", articles['product_type_name'].nunique())\nproduct_type_name_sorted = articles.groupby(['product_type_name']).count()['article_id'].sort_values(ascending=False)\nproduct_type_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:15.465196Z","iopub.execute_input":"2022-03-18T03:28:15.465575Z","iopub.status.idle":"2022-03-18T03:28:15.667806Z","shell.execute_reply.started":"2022-03-18T03:28:15.465525Z","shell.execute_reply":"2022-03-18T03:28:15.666972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"product_type_top = articles.groupby(['product_type_name']).count()['article_id'].sort_values(ascending=False).head(20)\nproduct_type_top","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:15.669380Z","iopub.execute_input":"2022-03-18T03:28:15.669625Z","iopub.status.idle":"2022-03-18T03:28:15.861496Z","shell.execute_reply.started":"2022-03-18T03:28:15.669594Z","shell.execute_reply":"2022-03-18T03:28:15.860803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 7))\nax = sns.barplot(x=product_type_top.values, y=product_type_top.index, color='xkcd:blue')\nax.set_xlabel('count by product type name')\nax.set_ylabel('product type name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:15.862473Z","iopub.execute_input":"2022-03-18T03:28:15.862705Z","iopub.status.idle":"2022-03-18T03:28:16.288810Z","shell.execute_reply.started":"2022-03-18T03:28:15.862675Z","shell.execute_reply":"2022-03-18T03:28:16.288030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 30))\nax = sns.barplot(x=product_type_name_sorted.values, y=product_type_name_sorted.index, color='xkcd:blue')\nax.set_xlabel('count by product type name')\nax.set_ylabel('product type name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:16.290138Z","iopub.execute_input":"2022-03-18T03:28:16.290534Z","iopub.status.idle":"2022-03-18T03:28:18.471619Z","shell.execute_reply.started":"2022-03-18T03:28:16.290488Z","shell.execute_reply":"2022-03-18T03:28:18.470485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### product_group_name","metadata":{}},{"cell_type":"code","source":"# product_group_name\nprint(articles['product_group_name'].nunique())\nproduct_group_name_sorted = articles.groupby(['product_group_name']).count()['article_id'].sort_values(ascending=False)\nproduct_group_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:18.477939Z","iopub.execute_input":"2022-03-18T03:28:18.479004Z","iopub.status.idle":"2022-03-18T03:28:18.791834Z","shell.execute_reply.started":"2022-03-18T03:28:18.478954Z","shell.execute_reply":"2022-03-18T03:28:18.789047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=product_group_name_sorted.values, y=product_group_name_sorted.index, color='crimson')\nax.set_xlabel('count by product group name')\nax.set_ylabel('product group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:18.795335Z","iopub.execute_input":"2022-03-18T03:28:18.796799Z","iopub.status.idle":"2022-03-18T03:28:19.800595Z","shell.execute_reply.started":"2022-03-18T03:28:18.796745Z","shell.execute_reply":"2022-03-18T03:28:19.798181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pie_data = product_group_name_sorted[product_group_name_sorted.values > 100]\npie_data","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:19.802849Z","iopub.execute_input":"2022-03-18T03:28:19.803318Z","iopub.status.idle":"2022-03-18T03:28:19.815534Z","shell.execute_reply.started":"2022-03-18T03:28:19.803281Z","shell.execute_reply":"2022-03-18T03:28:19.814149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(16, 8))\ncolors = sns.color_palette('pastel')\nax.pie(pie_data, labels=pie_data.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:19.817558Z","iopub.execute_input":"2022-03-18T03:28:19.818643Z","iopub.status.idle":"2022-03-18T03:28:20.300092Z","shell.execute_reply.started":"2022-03-18T03:28:19.818598Z","shell.execute_reply":"2022-03-18T03:28:20.296931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### product_group_name & product_type_name","metadata":{}},{"cell_type":"code","source":"# product_group_name, product_type_name\narticles.groupby(['product_group_name', 'product_type_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:20.304815Z","iopub.execute_input":"2022-03-18T03:28:20.307277Z","iopub.status.idle":"2022-03-18T03:28:20.660284Z","shell.execute_reply.started":"2022-03-18T03:28:20.307084Z","shell.execute_reply":"2022-03-18T03:28:20.657822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### graphical_appearance_name","metadata":{}},{"cell_type":"code","source":"# graphical_appearance_name\nprint(articles['graphical_appearance_name'].nunique())\ngraphical_appearance_name_sorted = articles.groupby('graphical_appearance_name').count()['article_id'].sort_values(ascending=False)\ngraphical_appearance_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:20.661861Z","iopub.execute_input":"2022-03-18T03:28:20.662215Z","iopub.status.idle":"2022-03-18T03:28:20.998606Z","shell.execute_reply.started":"2022-03-18T03:28:20.662177Z","shell.execute_reply":"2022-03-18T03:28:20.996623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 10))\nax = sns.barplot(x=graphical_appearance_name_sorted.values, y=graphical_appearance_name_sorted.index, color='xkcd:orangered')\nax.set_xlabel('count by graphical_appearance_name')\nax.set_ylabel('graphical_appearance_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:21.001491Z","iopub.execute_input":"2022-03-18T03:28:21.002495Z","iopub.status.idle":"2022-03-18T03:28:21.862537Z","shell.execute_reply.started":"2022-03-18T03:28:21.002342Z","shell.execute_reply":"2022-03-18T03:28:21.860388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### colour_group_name","metadata":{}},{"cell_type":"code","source":"# colour_group_name\nprint(articles['colour_group_name'].nunique())\ncolour_group_name_sorted = articles.groupby(['colour_group_name']).count()['article_id'].sort_values(ascending=False)\ncolour_group_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:21.866674Z","iopub.execute_input":"2022-03-18T03:28:21.867475Z","iopub.status.idle":"2022-03-18T03:28:22.091030Z","shell.execute_reply.started":"2022-03-18T03:28:21.867322Z","shell.execute_reply":"2022-03-18T03:28:22.090074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 15))\nax = sns.barplot(x=colour_group_name_sorted.values, y=colour_group_name_sorted.index, color='purple')\nax.set_xlabel('count by colour_group_name')\nax.set_ylabel('colour_group_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:22.092401Z","iopub.execute_input":"2022-03-18T03:28:22.092744Z","iopub.status.idle":"2022-03-18T03:28:22.979854Z","shell.execute_reply.started":"2022-03-18T03:28:22.092701Z","shell.execute_reply":"2022-03-18T03:28:22.979155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### perceived_colour_value_name","metadata":{}},{"cell_type":"code","source":"# perceived_colour_value_name\nprint(articles['perceived_colour_value_name'].nunique())\narticles.groupby(['perceived_colour_value_name']).count()['article_id'].sort_values(ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:22.981237Z","iopub.execute_input":"2022-03-18T03:28:22.981490Z","iopub.status.idle":"2022-03-18T03:28:23.181614Z","shell.execute_reply.started":"2022-03-18T03:28:22.981458Z","shell.execute_reply":"2022-03-18T03:28:23.180617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 3))\nax = sns.histplot(data=articles, y='perceived_colour_value_name', color='xkcd:coral')\nax.set_xlabel('count by perceived_colour_value_name')\nax.set_ylabel('perceived_colour_value_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:23.182960Z","iopub.execute_input":"2022-03-18T03:28:23.183210Z","iopub.status.idle":"2022-03-18T03:28:23.619536Z","shell.execute_reply.started":"2022-03-18T03:28:23.183180Z","shell.execute_reply":"2022-03-18T03:28:23.618666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### perceived_colour_master_name","metadata":{}},{"cell_type":"code","source":"# perceived_colour_master_name\nprint(articles['perceived_colour_master_name'].nunique())\nperceived_colour_master_name_sorted = articles.groupby(['perceived_colour_master_name']).count()['article_id'].sort_values(ascending=False)\nperceived_colour_master_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:23.620932Z","iopub.execute_input":"2022-03-18T03:28:23.621180Z","iopub.status.idle":"2022-03-18T03:28:23.819423Z","shell.execute_reply.started":"2022-03-18T03:28:23.621150Z","shell.execute_reply":"2022-03-18T03:28:23.818531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=perceived_colour_master_name_sorted.values, y=perceived_colour_master_name_sorted.index, color='darkgreen')\nax.set_xlabel('count by perceived_colour_master_name')\nax.set_ylabel('perceived_colour_master_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:23.820866Z","iopub.execute_input":"2022-03-18T03:28:23.821754Z","iopub.status.idle":"2022-03-18T03:28:24.181694Z","shell.execute_reply.started":"2022-03-18T03:28:23.821682Z","shell.execute_reply":"2022-03-18T03:28:24.180670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### department_name","metadata":{}},{"cell_type":"code","source":"# department_name\npd.options.display.max_rows = None\nprint(articles['department_name'].nunique())\ndepartment_name_sorted = articles.groupby(['department_name']).count()['article_id'].sort_values(ascending=False)\ndepartment_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:24.183491Z","iopub.execute_input":"2022-03-18T03:28:24.183981Z","iopub.status.idle":"2022-03-18T03:28:24.386597Z","shell.execute_reply.started":"2022-03-18T03:28:24.183944Z","shell.execute_reply":"2022-03-18T03:28:24.385725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 50))\nax = sns.barplot(x=department_name_sorted.values, y=department_name_sorted.index, color='teal')\nax.set_xlabel('count by department_name')\nax.set_ylabel('department_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:24.387857Z","iopub.execute_input":"2022-03-18T03:28:24.388064Z","iopub.status.idle":"2022-03-18T03:28:28.600727Z","shell.execute_reply.started":"2022-03-18T03:28:24.388039Z","shell.execute_reply":"2022-03-18T03:28:28.599906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### index_group_name","metadata":{}},{"cell_type":"code","source":"# index_group_name, index_name\narticles.groupby(['index_group_name', 'index_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:28.602376Z","iopub.execute_input":"2022-03-18T03:28:28.602608Z","iopub.status.idle":"2022-03-18T03:28:28.789753Z","shell.execute_reply.started":"2022-03-18T03:28:28.602581Z","shell.execute_reply":"2022-03-18T03:28:28.788821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# index_group_name\nindex_group_name_sorted = articles.groupby(['index_group_name']).count()['article_id'].sort_values(ascending=False)\nindex_group_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:28.791235Z","iopub.execute_input":"2022-03-18T03:28:28.791577Z","iopub.status.idle":"2022-03-18T03:28:28.981369Z","shell.execute_reply.started":"2022-03-18T03:28:28.791543Z","shell.execute_reply":"2022-03-18T03:28:28.980432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 2))\nax = sns.barplot(x=index_group_name_sorted.values, y=index_group_name_sorted.index, color='indigo')\nax.set_xlabel('count by index group name')\nax.set_ylabel('index group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:28.983244Z","iopub.execute_input":"2022-03-18T03:28:28.983526Z","iopub.status.idle":"2022-03-18T03:28:29.248911Z","shell.execute_reply.started":"2022-03-18T03:28:28.983496Z","shell.execute_reply":"2022-03-18T03:28:29.248020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\ncolors = sns.color_palette('pastel')\nax.pie(index_group_name_sorted, labels=index_group_name_sorted.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:29.250335Z","iopub.execute_input":"2022-03-18T03:28:29.250561Z","iopub.status.idle":"2022-03-18T03:28:29.392177Z","shell.execute_reply.started":"2022-03-18T03:28:29.250534Z","shell.execute_reply":"2022-03-18T03:28:29.390877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### index_name","metadata":{}},{"cell_type":"code","source":"# index_name\nindex_name_sorted = articles.groupby(['index_name']).count()['article_id'].sort_values(ascending=False)\nindex_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:29.397673Z","iopub.execute_input":"2022-03-18T03:28:29.398597Z","iopub.status.idle":"2022-03-18T03:28:29.626369Z","shell.execute_reply.started":"2022-03-18T03:28:29.398529Z","shell.execute_reply":"2022-03-18T03:28:29.625014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 3))\nax = sns.barplot(x=index_name_sorted.values, y=index_name_sorted.index, color='teal')\nax.set_xlabel('count by index name')\nax.set_ylabel('index name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:29.628327Z","iopub.execute_input":"2022-03-18T03:28:29.629069Z","iopub.status.idle":"2022-03-18T03:28:29.924705Z","shell.execute_reply.started":"2022-03-18T03:28:29.629013Z","shell.execute_reply":"2022-03-18T03:28:29.923788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### section_name","metadata":{}},{"cell_type":"code","source":"# section_name\nprint(articles['section_name'].nunique())\nsection_name_sorted = articles.groupby(['section_name']).count()['article_id'].sort_values(ascending=False)\nsection_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:29.926297Z","iopub.execute_input":"2022-03-18T03:28:29.926669Z","iopub.status.idle":"2022-03-18T03:28:30.125171Z","shell.execute_reply.started":"2022-03-18T03:28:29.926637Z","shell.execute_reply":"2022-03-18T03:28:30.124153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 13))\nax = sns.barplot(x=section_name_sorted.values, y=section_name_sorted.index, color='teal')\nax.set_xlabel('count by section_name')\nax.set_ylabel('section_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:30.126786Z","iopub.execute_input":"2022-03-18T03:28:30.127203Z","iopub.status.idle":"2022-03-18T03:28:31.272455Z","shell.execute_reply.started":"2022-03-18T03:28:30.127168Z","shell.execute_reply":"2022-03-18T03:28:31.270210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### garment_group_name","metadata":{}},{"cell_type":"code","source":"# garment_group_name\nprint(articles['garment_group_name'].nunique())\ngarment_group_name_sorted = articles.groupby(['garment_group_name']).count()['article_id'].sort_values(ascending=False)\ngarment_group_name_sorted","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:31.274243Z","iopub.execute_input":"2022-03-18T03:28:31.274805Z","iopub.status.idle":"2022-03-18T03:28:31.491604Z","shell.execute_reply.started":"2022-03-18T03:28:31.274708Z","shell.execute_reply":"2022-03-18T03:28:31.490712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=garment_group_name_sorted.values, y=garment_group_name_sorted.index, color='xkcd:magenta')\nax.set_xlabel('count by garment_group_name')\nax.set_ylabel('garment_group_name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:31.493305Z","iopub.execute_input":"2022-03-18T03:28:31.493826Z","iopub.status.idle":"2022-03-18T03:28:31.872537Z","shell.execute_reply.started":"2022-03-18T03:28:31.493779Z","shell.execute_reply":"2022-03-18T03:28:31.871484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"customers\"></a>\n# Customers","metadata":{}},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:31.874402Z","iopub.execute_input":"2022-03-18T03:28:31.874750Z","iopub.status.idle":"2022-03-18T03:28:31.892114Z","shell.execute_reply.started":"2022-03-18T03:28:31.874690Z","shell.execute_reply":"2022-03-18T03:28:31.890841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:31.893752Z","iopub.execute_input":"2022-03-18T03:28:31.894154Z","iopub.status.idle":"2022-03-18T03:28:32.574062Z","shell.execute_reply.started":"2022-03-18T03:28:31.894090Z","shell.execute_reply":"2022-03-18T03:28:32.573055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:32.582017Z","iopub.execute_input":"2022-03-18T03:28:32.582299Z","iopub.status.idle":"2022-03-18T03:28:32.789300Z","shell.execute_reply.started":"2022-03-18T03:28:32.582269Z","shell.execute_reply":"2022-03-18T03:28:32.788047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:32.791101Z","iopub.execute_input":"2022-03-18T03:28:32.791458Z","iopub.status.idle":"2022-03-18T03:28:34.569159Z","shell.execute_reply.started":"2022-03-18T03:28:32.791405Z","shell.execute_reply":"2022-03-18T03:28:34.568176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"unique_values_customers\"></a>\n### Unique values of each column","metadata":{}},{"cell_type":"code","source":"for c in customers.columns:\n    print(\"{} ({}) {} => {}\".format(c, customers[c].nunique(), type(customers[c].iloc[0]), customers[c].unique()))","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:34.570886Z","iopub.execute_input":"2022-03-18T03:28:34.571219Z","iopub.status.idle":"2022-03-18T03:28:37.809263Z","shell.execute_reply.started":"2022-03-18T03:28:34.571175Z","shell.execute_reply":"2022-03-18T03:28:37.808245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for c in ['FN','Active','club_member_status', 'fashion_news_frequency']:\n    print('[{}] :\\n{}\\n'.format(c, customers[c].value_counts(dropna=False)))","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:37.810617Z","iopub.execute_input":"2022-03-18T03:28:37.811352Z","iopub.status.idle":"2022-03-18T03:28:38.283293Z","shell.execute_reply.started":"2022-03-18T03:28:37.811316Z","shell.execute_reply":"2022-03-18T03:28:38.282353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### FN","metadata":{}},{"cell_type":"markdown","source":"### Active","metadata":{}},{"cell_type":"markdown","source":"### club_member_status","metadata":{}},{"cell_type":"code","source":"# club_member_status\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customers, x='club_member_status', color='green')\nax.set_xlabel('customers club_member_status')\nax.set_ylabel('customer count')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:38.284520Z","iopub.execute_input":"2022-03-18T03:28:38.284781Z","iopub.status.idle":"2022-03-18T03:28:40.351090Z","shell.execute_reply.started":"2022-03-18T03:28:38.284747Z","shell.execute_reply":"2022-03-18T03:28:40.350065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### fashion_news_frequency","metadata":{}},{"cell_type":"code","source":"# fashion_news_frequency\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customers, x='fashion_news_frequency', color='orange')\nax.set_xlabel('customers fashion_news_frequency')\nax.set_ylabel('customer count')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:40.352420Z","iopub.execute_input":"2022-03-18T03:28:40.352692Z","iopub.status.idle":"2022-03-18T03:28:42.432666Z","shell.execute_reply.started":"2022-03-18T03:28:40.352660Z","shell.execute_reply":"2022-03-18T03:28:42.431371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### age","metadata":{}},{"cell_type":"code","source":"# age\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customers, x='age', bins=50, color='xkcd:azure')\nax.set_xlabel('customers age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:42.434037Z","iopub.execute_input":"2022-03-18T03:28:42.434288Z","iopub.status.idle":"2022-03-18T03:28:43.010151Z","shell.execute_reply.started":"2022-03-18T03:28:42.434259Z","shell.execute_reply":"2022-03-18T03:28:43.009032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# average description\ncustomers['age'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:43.011487Z","iopub.execute_input":"2022-03-18T03:28:43.011756Z","iopub.status.idle":"2022-03-18T03:28:43.075875Z","shell.execute_reply.started":"2022-03-18T03:28:43.011702Z","shell.execute_reply":"2022-03-18T03:28:43.074969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nfrom matplotlib import pyplot as plt\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,2))\nax = sns.boxplot(data=customers, x='age', color='xkcd:azure')\nax.set_xlabel('customers age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:43.077322Z","iopub.execute_input":"2022-03-18T03:28:43.077572Z","iopub.status.idle":"2022-03-18T03:28:43.542043Z","shell.execute_reply.started":"2022-03-18T03:28:43.077542Z","shell.execute_reply":"2022-03-18T03:28:43.541365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# age description with ACTIVE club_member_status\ncustomers[customers['club_member_status']== 'ACTIVE']['age'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:43.543389Z","iopub.execute_input":"2022-03-18T03:28:43.543652Z","iopub.status.idle":"2022-03-18T03:28:43.957796Z","shell.execute_reply.started":"2022-03-18T03:28:43.543621Z","shell.execute_reply":"2022-03-18T03:28:43.956809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# age description who fashion_news_frequency is 'Regularly'\ncustomers[customers['fashion_news_frequency']== 'Regularly']['age'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:43.959269Z","iopub.execute_input":"2022-03-18T03:28:43.960226Z","iopub.status.idle":"2022-03-18T03:28:44.268477Z","shell.execute_reply.started":"2022-03-18T03:28:43.960177Z","shell.execute_reply":"2022-03-18T03:28:44.267463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## postal_code","metadata":{}},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=transactions></a>\n# Transactions","metadata":{}},{"cell_type":"code","source":"transactions_train.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:44.269885Z","iopub.execute_input":"2022-03-18T03:28:44.270203Z","iopub.status.idle":"2022-03-18T03:28:44.284223Z","shell.execute_reply.started":"2022-03-18T03:28:44.270159Z","shell.execute_reply":"2022-03-18T03:28:44.283053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:44.285474Z","iopub.execute_input":"2022-03-18T03:28:44.285756Z","iopub.status.idle":"2022-03-18T03:28:44.302897Z","shell.execute_reply.started":"2022-03-18T03:28:44.285693Z","shell.execute_reply":"2022-03-18T03:28:44.301869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.float_format', '{:.4f}'.format)\ntransactions_train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:44.304070Z","iopub.execute_input":"2022-03-18T03:28:44.304487Z","iopub.status.idle":"2022-03-18T03:28:47.611860Z","shell.execute_reply.started":"2022-03-18T03:28:44.304449Z","shell.execute_reply":"2022-03-18T03:28:47.610994Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:28:47.613274Z","iopub.execute_input":"2022-03-18T03:28:47.614006Z","iopub.status.idle":"2022-03-18T03:29:00.204490Z","shell.execute_reply.started":"2022-03-18T03:28:47.613969Z","shell.execute_reply":"2022-03-18T03:29:00.203595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### t_dat","metadata":{}},{"cell_type":"code","source":"transactions_train['t_dat'].head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:00.206111Z","iopub.execute_input":"2022-03-18T03:29:00.206748Z","iopub.status.idle":"2022-03-18T03:29:00.215321Z","shell.execute_reply.started":"2022-03-18T03:29:00.206679Z","shell.execute_reply":"2022-03-18T03:29:00.214380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train['t_dat'].tail()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:00.216983Z","iopub.execute_input":"2022-03-18T03:29:00.217214Z","iopub.status.idle":"2022-03-18T03:29:00.229964Z","shell.execute_reply.started":"2022-03-18T03:29:00.217187Z","shell.execute_reply":"2022-03-18T03:29:00.228837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### sales_channel_id","metadata":{}},{"cell_type":"code","source":"# sales_channel_id\ntransactions_train['sales_channel_id'].value_counts(dropna=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:00.231439Z","iopub.execute_input":"2022-03-18T03:29:00.231799Z","iopub.status.idle":"2022-03-18T03:29:00.405264Z","shell.execute_reply.started":"2022-03-18T03:29:00.231763Z","shell.execute_reply":"2022-03-18T03:29:00.404373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### price","metadata":{}},{"cell_type":"code","source":"# price\npd.set_option('display.float_format', '{:.4f}'.format)\ntransactions_train.describe()['price']","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:00.406425Z","iopub.execute_input":"2022-03-18T03:29:00.407122Z","iopub.status.idle":"2022-03-18T03:29:03.724108Z","shell.execute_reply.started":"2022-03-18T03:29:00.407089Z","shell.execute_reply":"2022-03-18T03:29:03.723118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# highest price\ntransactions_train.price.sort_values(ascending=False).head(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:03.726252Z","iopub.execute_input":"2022-03-18T03:29:03.726918Z","iopub.status.idle":"2022-03-18T03:29:10.753447Z","shell.execute_reply.started":"2022-03-18T03:29:03.726865Z","shell.execute_reply":"2022-03-18T03:29:10.752520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# lowest price\ntransactions_train.price.sort_values(ascending=False).tail(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:10.754744Z","iopub.execute_input":"2022-03-18T03:29:10.754985Z","iopub.status.idle":"2022-03-18T03:29:17.769762Z","shell.execute_reply.started":"2022-03-18T03:29:10.754955Z","shell.execute_reply":"2022-03-18T03:29:17.768876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"price_distribution\"></a>\n# Price Distribution","metadata":{}},{"cell_type":"markdown","source":"### Drawing Price Distribution","metadata":{}},{"cell_type":"code","source":"# price\nimport seaborn as sns\nfrom matplotlib import pyplot as plt\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(20, 5))\nax = sns.histplot(data=transactions_train, x='price', bins=100, color='xkcd:teal')\nax.set_xlabel('price')\nax.set_xlabel('transacion count')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:17.771089Z","iopub.execute_input":"2022-03-18T03:29:17.771334Z","iopub.status.idle":"2022-03-18T03:29:28.125728Z","shell.execute_reply.started":"2022-03-18T03:29:17.771303Z","shell.execute_reply":"2022-03-18T03:29:28.124768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Check Price Outliers","metadata":{}},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(20,1))\nax = sns.boxplot(data=transactions_train, x='price', color='xkcd:pink')\nax.set_xlabel('Price outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:28.127083Z","iopub.execute_input":"2022-03-18T03:29:28.127343Z","iopub.status.idle":"2022-03-18T03:29:32.799949Z","shell.execute_reply.started":"2022-03-18T03:29:28.127311Z","shell.execute_reply":"2022-03-18T03:29:32.798771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"top_selling_articles\"></a>\n# Top Selling Articles","metadata":{}},{"cell_type":"markdown","source":"### Top selling article by total sales","metadata":{}},{"cell_type":"code","source":"# top selling article by total sales\ntop_selling_article_by_total_sales = transactions_train.groupby('article_id')['price'].sum().sort_values(ascending=False).head(20)\ntop_selling_article_by_total_sales","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:32.801491Z","iopub.execute_input":"2022-03-18T03:29:32.801815Z","iopub.status.idle":"2022-03-18T03:29:34.060536Z","shell.execute_reply.started":"2022-03-18T03:29:32.801776Z","shell.execute_reply":"2022-03-18T03:29:34.059387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Categories of top selling articles by total sales","metadata":{}},{"cell_type":"code","source":"# check category of top selling artichles\nfor i, idx in enumerate(top_selling_article_by_total_sales.index):    \n    print(\"[{}] {} ==> {}\".format(i, idx,articles[articles['article_id'] == idx][['product_group_name','product_type_name','index_name', 'garment_group_name']].values[0]))","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:34.062870Z","iopub.execute_input":"2022-03-18T03:29:34.063155Z","iopub.status.idle":"2022-03-18T03:29:34.102998Z","shell.execute_reply.started":"2022-03-18T03:29:34.063119Z","shell.execute_reply":"2022-03-18T03:29:34.102013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.image as img\n\ndef get_image_path(article_num):\n    path = '/kaggle/input/h-and-m-personalized-fashion-recommendations/images/'\n    article_str = f'{article_num:010d}'\n    dir_str = f'{int(article_num/10**7):03d}'\n    return path+dir_str+'/'+article_str+'.jpg'\n\ndef draw_article_images(articles_seq):\n    sns.set_style(\"white\")\n    cols = 5\n    rows = int(len(articles_seq) / cols)\n    fig = plt.figure(figsize=(20, 5*rows))\n    for i, idx in enumerate(articles_seq):\n        try:\n            article_num = idx\n            path = get_image_path(article_num)\n            image = img.imread(path)\n            ax = fig.add_subplot(rows, cols, i+1)\n            ax.imshow(image)\n        except FileNotFoundError:\n            print(path+' : file not found')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:34.104871Z","iopub.execute_input":"2022-03-18T03:29:34.105474Z","iopub.status.idle":"2022-03-18T03:29:34.115946Z","shell.execute_reply.started":"2022-03-18T03:29:34.105425Z","shell.execute_reply":"2022-03-18T03:29:34.114831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Images of top selling article by total sales","metadata":{}},{"cell_type":"code","source":"# drawing images of top selling articles by total sales\ndraw_article_images(top_selling_article_by_total_sales.index)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:34.117993Z","iopub.execute_input":"2022-03-18T03:29:34.118355Z","iopub.status.idle":"2022-03-18T03:29:42.389348Z","shell.execute_reply.started":"2022-03-18T03:29:34.118307Z","shell.execute_reply":"2022-03-18T03:29:42.388278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Top selling articles by number","metadata":{}},{"cell_type":"code","source":"# Best selling article by number\ntop_selling_article_by_number = transactions_train.groupby('article_id').count()['t_dat'].sort_values(ascending=False).head(20)\ntop_selling_article_by_number","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:42.390865Z","iopub.execute_input":"2022-03-18T03:29:42.391772Z","iopub.status.idle":"2022-03-18T03:29:51.731756Z","shell.execute_reply.started":"2022-03-18T03:29:42.391731Z","shell.execute_reply":"2022-03-18T03:29:51.730798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Categories of top selling articles by number","metadata":{}},{"cell_type":"code","source":"for i, idx in enumerate(top_selling_article_by_number.index):\n    print(\"[{}] {} ==> {}\".format(i, idx, articles[articles['article_id'] == idx][['product_group_name','product_type_name','index_name', 'garment_group_name']].values[0]))","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:51.733044Z","iopub.execute_input":"2022-03-18T03:29:51.733298Z","iopub.status.idle":"2022-03-18T03:29:51.775085Z","shell.execute_reply.started":"2022-03-18T03:29:51.733267Z","shell.execute_reply":"2022-03-18T03:29:51.773971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Images of top selling articles by number","metadata":{}},{"cell_type":"code","source":"# drawing images of top selling articles by number\ndraw_article_images(top_selling_article_by_number.index)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:51.776691Z","iopub.execute_input":"2022-03-18T03:29:51.777072Z","iopub.status.idle":"2022-03-18T03:29:59.039962Z","shell.execute_reply.started":"2022-03-18T03:29:51.777023Z","shell.execute_reply":"2022-03-18T03:29:59.038939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"top_customers\"></a>\n# Top 10 Customers","metadata":{}},{"cell_type":"markdown","source":"### Top 10 customers with the most purchases","metadata":{}},{"cell_type":"code","source":"# top 10 customers with the most purchases\ntop_customers_by_purchases = transactions_train.groupby('customer_id').count()['t_dat'].sort_values(ascending=False).head(10)\ntop_customers_by_purchases","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:29:59.041218Z","iopub.execute_input":"2022-03-18T03:29:59.041480Z","iopub.status.idle":"2022-03-18T03:30:18.210550Z","shell.execute_reply.started":"2022-03-18T03:29:59.041448Z","shell.execute_reply":"2022-03-18T03:30:18.209908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Ages of top 10 customers","metadata":{}},{"cell_type":"code","source":"# age of top 10 customers\nfor i, idx in enumerate(top_customers_by_purchases.index):    \n    print(\"[{}] {} ==> {}\".format(i, idx, customers[customers['customer_id'] == idx]['age'].values[0]))","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:30:18.211656Z","iopub.execute_input":"2022-03-18T03:30:18.212379Z","iopub.status.idle":"2022-03-18T03:30:20.452754Z","shell.execute_reply.started":"2022-03-18T03:30:18.212335Z","shell.execute_reply":"2022-03-18T03:30:20.451735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Top 10 customers by purchase amount","metadata":{}},{"cell_type":"code","source":"# top 10 customers by purchase amount\ntop_customers_by_largest_purchases = transactions_train.groupby('customer_id')['price'].sum().sort_values(ascending=False).head(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:30:20.454609Z","iopub.execute_input":"2022-03-18T03:30:20.454961Z","iopub.status.idle":"2022-03-18T03:30:35.558166Z","shell.execute_reply.started":"2022-03-18T03:30:20.454907Z","shell.execute_reply":"2022-03-18T03:30:35.557025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Ages of top 10 customers","metadata":{}},{"cell_type":"code","source":"# age of top 10 customers\nfor i, idx in enumerate(top_customers_by_largest_purchases.index):\n    print(\"[{}] {} ==> {}\".format(i, idx, customers[customers['customer_id'] == idx]['age'].values[0]))","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:30:35.559675Z","iopub.execute_input":"2022-03-18T03:30:35.559939Z","iopub.status.idle":"2022-03-18T03:30:37.763466Z","shell.execute_reply.started":"2022-03-18T03:30:35.559910Z","shell.execute_reply":"2022-03-18T03:30:37.762744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"price_outliers\"></a>\n# Price Outliers By Category","metadata":{}},{"cell_type":"code","source":"# merge transaction + customer + article\ntransactions_to_be_merged = transactions_train[['t_dat', 'customer_id', 'article_id', 'price']]\narticle_to_be_merged = articles[['article_id', 'prod_name', 'product_type_name', 'product_group_name', 'index_group_name']]\ncustomers_to_be_merged = customers[['customer_id', 'age']]\n\ntransactions_merged = transactions_to_be_merged.merge(article_to_be_merged, on='article_id', how='left')\ntransactions_merged = transactions_merged.merge(customers_to_be_merged, on='customer_id', how='left')\n\ntransactions_merged.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:30:37.764423Z","iopub.execute_input":"2022-03-18T03:30:37.764673Z","iopub.status.idle":"2022-03-18T03:31:08.437754Z","shell.execute_reply.started":"2022-03-18T03:30:37.764642Z","shell.execute_reply":"2022-03-18T03:31:08.436803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"produt_group_names = transactions_merged['product_group_name'].unique()\nprodut_group_names","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:31:08.440177Z","iopub.execute_input":"2022-03-18T03:31:08.440751Z","iopub.status.idle":"2022-03-18T03:31:11.397092Z","shell.execute_reply.started":"2022-03-18T03:31:08.440685Z","shell.execute_reply":"2022-03-18T03:31:11.396217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"box_color = ['xkcd:pink', 'xkcd:blue', 'xkcd:teal', 'xkcd:goldenrod']\nsns.set_style(\"darkgrid\")\nfor i, name in enumerate(produt_group_names):\n    figure, ax = plt.subplots(figsize=(20,1))\n    ax = sns.boxplot(data=transactions_merged[transactions_merged['product_group_name']== name], x='price', color=box_color[i%len(box_color)])\n    plt.xticks(np.arange(-0.05, 0.7, step=0.05))\n    ax.set_ylabel(name)\n    plt.show()\nax.set_xlabel('Price outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:31:11.398534Z","iopub.execute_input":"2022-03-18T03:31:11.398785Z","iopub.status.idle":"2022-03-18T03:32:59.539288Z","shell.execute_reply.started":"2022-03-18T03:31:11.398754Z","shell.execute_reply":"2022-03-18T03:32:59.538263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"top_selling_product_group\"></a>\n# Top Selling Product Group","metadata":{}},{"cell_type":"markdown","source":"### Top selling product group by total sales","metadata":{}},{"cell_type":"code","source":"# top selling product group by total sales\ntop_selling_product_group = transactions_merged.groupby('product_group_name')['price'].sum().sort_values(ascending=False)\ntop_selling_product_group","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:32:59.541163Z","iopub.execute_input":"2022-03-18T03:32:59.541703Z","iopub.status.idle":"2022-03-18T03:33:03.199405Z","shell.execute_reply.started":"2022-03-18T03:32:59.541656Z","shell.execute_reply":"2022-03-18T03:33:03.197764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=top_selling_product_group.values, y=top_selling_product_group.index, color='xkcd:magenta')\nax.set_xlabel('total sales by product group name')\nax.set_ylabel('product group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:03.201025Z","iopub.execute_input":"2022-03-18T03:33:03.201579Z","iopub.status.idle":"2022-03-18T03:33:03.609779Z","shell.execute_reply.started":"2022-03-18T03:33:03.201527Z","shell.execute_reply":"2022-03-18T03:33:03.608809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(16, 8))\ncolors = sns.color_palette('pastel')\nax.pie(top_selling_product_group, labels=top_selling_product_group.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:03.611334Z","iopub.execute_input":"2022-03-18T03:33:03.611657Z","iopub.status.idle":"2022-03-18T03:33:03.928237Z","shell.execute_reply.started":"2022-03-18T03:33:03.611612Z","shell.execute_reply":"2022-03-18T03:33:03.927482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Top selling product group by number","metadata":{}},{"cell_type":"code","source":"# top selling prouct_group by number\ntop_selling_product_group_by_number = transactions_merged.groupby('product_group_name')['article_id'].count().sort_values(ascending=False)\ntop_selling_product_group_by_number","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:03.929239Z","iopub.execute_input":"2022-03-18T03:33:03.929944Z","iopub.status.idle":"2022-03-18T03:33:07.675748Z","shell.execute_reply.started":"2022-03-18T03:33:03.929902Z","shell.execute_reply":"2022-03-18T03:33:07.675031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 6))\nax = sns.barplot(x=top_selling_product_group_by_number.values, y=top_selling_product_group_by_number.index, color='xkcd:blue')\nax.set_xlabel('top selling group by number')\nax.set_ylabel('product group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:07.676765Z","iopub.execute_input":"2022-03-18T03:33:07.677441Z","iopub.status.idle":"2022-03-18T03:33:08.058071Z","shell.execute_reply.started":"2022-03-18T03:33:07.677408Z","shell.execute_reply":"2022-03-18T03:33:08.057352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(16, 8))\ncolors = sns.color_palette('pastel')\nax.pie(top_selling_product_group_by_number, labels=top_selling_product_group_by_number.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:08.059287Z","iopub.execute_input":"2022-03-18T03:33:08.059649Z","iopub.status.idle":"2022-03-18T03:33:08.377083Z","shell.execute_reply.started":"2022-03-18T03:33:08.059618Z","shell.execute_reply":"2022-03-18T03:33:08.376268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Top selling index group by total sales","metadata":{}},{"cell_type":"code","source":"# top selling index_group by total sales\ntop_selling_index_group = transactions_merged.groupby('index_group_name')['price'].sum().sort_values(ascending=False)\ntop_selling_index_group","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:08.378268Z","iopub.execute_input":"2022-03-18T03:33:08.378611Z","iopub.status.idle":"2022-03-18T03:33:11.775250Z","shell.execute_reply.started":"2022-03-18T03:33:08.378582Z","shell.execute_reply":"2022-03-18T03:33:11.774309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 2))\nax = sns.barplot(x=top_selling_index_group.values, y=top_selling_index_group.index, color='xkcd:magenta')\nax.set_xlabel('total sales by index group name')\nax.set_ylabel('index group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:11.776677Z","iopub.execute_input":"2022-03-18T03:33:11.776960Z","iopub.status.idle":"2022-03-18T03:33:12.216777Z","shell.execute_reply.started":"2022-03-18T03:33:11.776928Z","shell.execute_reply":"2022-03-18T03:33:12.215576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 5))\ncolors = sns.color_palette('pastel')\nax.pie(top_selling_index_group, labels=top_selling_index_group.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:12.218233Z","iopub.execute_input":"2022-03-18T03:33:12.218547Z","iopub.status.idle":"2022-03-18T03:33:12.355902Z","shell.execute_reply.started":"2022-03-18T03:33:12.218507Z","shell.execute_reply":"2022-03-18T03:33:12.354600Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Top selling index group by number","metadata":{}},{"cell_type":"code","source":"# top selling index_group by number\ntop_selling_index_group_by_number = transactions_merged.groupby('index_group_name')['article_id'].count().sort_values(ascending=False)\ntop_selling_index_group_by_number","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:12.359618Z","iopub.execute_input":"2022-03-18T03:33:12.361298Z","iopub.status.idle":"2022-03-18T03:33:15.831545Z","shell.execute_reply.started":"2022-03-18T03:33:12.361239Z","shell.execute_reply":"2022-03-18T03:33:15.830502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,2))\nax = sns.barplot(x=top_selling_index_group_by_number.values, y=top_selling_index_group_by_number.index, color='xkcd:blue')\nax.set_xlabel('top selling group by number')\nax.set_ylabel('index group name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:15.833046Z","iopub.execute_input":"2022-03-18T03:33:15.833281Z","iopub.status.idle":"2022-03-18T03:33:16.108283Z","shell.execute_reply.started":"2022-03-18T03:33:15.833254Z","shell.execute_reply":"2022-03-18T03:33:16.107146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10, 5))\ncolors = sns.color_palette('pastel')\nax.pie(top_selling_index_group_by_number, labels=top_selling_index_group_by_number.index, colors = colors, autopct='%1.1f%%')\nax.set_facecolor('lightgrey')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:16.109909Z","iopub.execute_input":"2022-03-18T03:33:16.110185Z","iopub.status.idle":"2022-03-18T03:33:16.242527Z","shell.execute_reply.started":"2022-03-18T03:33:16.110156Z","shell.execute_reply":"2022-03-18T03:33:16.241339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"sales_distribution\"></a>\n# Sales Distribution","metadata":{}},{"cell_type":"code","source":"# total sales\ntotal_sales = transactions_train['price'].sum()\ntotal_sales","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:16.244967Z","iopub.execute_input":"2022-03-18T03:33:16.245477Z","iopub.status.idle":"2022-03-18T03:33:16.332573Z","shell.execute_reply.started":"2022-03-18T03:33:16.245418Z","shell.execute_reply":"2022-03-18T03:33:16.331627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# calcurate and sort sales for each article\narticle_sorted_by_sales = transactions_train.groupby('article_id')['price'].sum().sort_values(ascending=False)\narticle_sorted_by_sales.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:16.333896Z","iopub.execute_input":"2022-03-18T03:33:16.334110Z","iopub.status.idle":"2022-03-18T03:33:17.556115Z","shell.execute_reply.started":"2022-03-18T03:33:16.334084Z","shell.execute_reply":"2022-03-18T03:33:17.555366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_sorted_by_sales.tail()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:17.557499Z","iopub.execute_input":"2022-03-18T03:33:17.557962Z","iopub.status.idle":"2022-03-18T03:33:17.565058Z","shell.execute_reply.started":"2022-03-18T03:33:17.557929Z","shell.execute_reply":"2022-03-18T03:33:17.564027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# total number of articles\narticle_sorted_by_sales.shape[0]","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:17.566472Z","iopub.execute_input":"2022-03-18T03:33:17.566795Z","iopub.status.idle":"2022-03-18T03:33:17.579733Z","shell.execute_reply.started":"2022-03-18T03:33:17.566754Z","shell.execute_reply":"2022-03-18T03:33:17.578473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_sorted_by_sales.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:17.581322Z","iopub.execute_input":"2022-03-18T03:33:17.581671Z","iopub.status.idle":"2022-03-18T03:33:17.605478Z","shell.execute_reply.started":"2022-03-18T03:33:17.581625Z","shell.execute_reply":"2022-03-18T03:33:17.604597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Sales distribution of all articles","metadata":{}},{"cell_type":"code","source":"# sales distribution of all articleas\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(20, 5))\nax = sns.histplot(article_sorted_by_sales.values, bins=100, color='xkcd:blue')\nax.set_xlabel('distribution of sales')\nax.set_ylabel('sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:17.607095Z","iopub.execute_input":"2022-03-18T03:33:17.607594Z","iopub.status.idle":"2022-03-18T03:33:18.153578Z","shell.execute_reply.started":"2022-03-18T03:33:17.607550Z","shell.execute_reply":"2022-03-18T03:33:18.152609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Sales distribution of top 100 selling articles","metadata":{}},{"cell_type":"code","source":"# sales distribution of top 100 selling articles\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(20, 5))\nax = sns.histplot(article_sorted_by_sales.values[:100], bins=100, color='xkcd:blue')\nax.set_xlabel('distribution of sales')\nax.set_ylabel('sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:18.154950Z","iopub.execute_input":"2022-03-18T03:33:18.155610Z","iopub.status.idle":"2022-03-18T03:33:18.629669Z","shell.execute_reply.started":"2022-03-18T03:33:18.155571Z","shell.execute_reply":"2022-03-18T03:33:18.628761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Sales graph of articles sorted by sales volume","metadata":{}},{"cell_type":"code","source":"# sales graph of articles sorted by sales volume\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(8,8))\nax = sns.lineplot(x=range(article_sorted_by_sales.shape[0]), y=article_sorted_by_sales.values, color='xkcd:blue')\nax.set_xlabel('article sales ranking')\nax.set_ylabel('sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:18.630922Z","iopub.execute_input":"2022-03-18T03:33:18.631185Z","iopub.status.idle":"2022-03-18T03:33:23.174816Z","shell.execute_reply.started":"2022-03-18T03:33:18.631156Z","shell.execute_reply":"2022-03-18T03:33:23.173797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### How much top selling 1% articles contribute to overall sales","metadata":{}},{"cell_type":"code","source":"# how much top selling 1% articles contribute to overall sales\ntop_1p_articles = article_sorted_by_sales.head(int(article_sorted_by_sales.shape[0]*0.01))\ntop_1p_articles.sum()/ total_sales","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:23.176196Z","iopub.execute_input":"2022-03-18T03:33:23.176448Z","iopub.status.idle":"2022-03-18T03:33:23.184431Z","shell.execute_reply.started":"2022-03-18T03:33:23.176422Z","shell.execute_reply":"2022-03-18T03:33:23.183248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### How much top selling n% articles contribute to overall sales","metadata":{}},{"cell_type":"code","source":"# how much top selling n% articles contribute to overall sales\nn_pct_sales = [article_sorted_by_sales.head(int(article_sorted_by_sales.shape[0]*0.01*(n))).sum() / total_sales * 100 for n in range (1, 100+1)]\n# n_pct_sales","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:23.186605Z","iopub.execute_input":"2022-03-18T03:33:23.187065Z","iopub.status.idle":"2022-03-18T03:33:23.216069Z","shell.execute_reply.started":"2022-03-18T03:33:23.187013Z","shell.execute_reply":"2022-03-18T03:33:23.214765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# top selling n% articles => contribution percentage to total sales\nfor n in range(100):\n    print(\"{:3}% => {:3.2f} % sales (+{:3.2f})%\".format(n+1, n_pct_sales[n], n_pct_sales[n] - n_pct_sales[n-1] if n>0 else 0))\n    print(\"-------------------------------\") if (n+1) % 10 == 0 and (n+1) != 0 else 0","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:23.217475Z","iopub.execute_input":"2022-03-18T03:33:23.217746Z","iopub.status.idle":"2022-03-18T03:33:23.238622Z","shell.execute_reply.started":"2022-03-18T03:33:23.217699Z","shell.execute_reply":"2022-03-18T03:33:23.231310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(6,6))\nax = sns.lineplot(x=range(1, 100+1), y=n_pct_sales, color='xkcd:blue')\nax.set_xlabel('n percent articles')\nax.set_ylabel('sales')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:23.240166Z","iopub.execute_input":"2022-03-18T03:33:23.240527Z","iopub.status.idle":"2022-03-18T03:33:23.502061Z","shell.execute_reply.started":"2022-03-18T03:33:23.240491Z","shell.execute_reply":"2022-03-18T03:33:23.501129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Top 20% account for 80% of total sales  => Pareto principle \n\n### Long tail is not observed in this data.","metadata":{}},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=\"sales_volume_change\"></a>\n# Changes in sales volume due to price changes\n\n### The same article has different prices, so let's check the sales volume change according to the price change.","metadata":{}},{"cell_type":"code","source":"article_sorted_by_sales.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:23.503735Z","iopub.execute_input":"2022-03-18T03:33:23.504697Z","iopub.status.idle":"2022-03-18T03:33:23.513675Z","shell.execute_reply.started":"2022-03-18T03:33:23.504645Z","shell.execute_reply":"2022-03-18T03:33:23.512520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_1_selling_article = transactions_train[transactions_train['article_id'] == article_sorted_by_sales.index[0]]\ntop_1_selling_article.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:23.514951Z","iopub.execute_input":"2022-03-18T03:33:23.515293Z","iopub.status.idle":"2022-03-18T03:33:23.606039Z","shell.execute_reply.started":"2022-03-18T03:33:23.515248Z","shell.execute_reply":"2022-03-18T03:33:23.605005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_1_selling_article['price'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:23.607688Z","iopub.execute_input":"2022-03-18T03:33:23.607989Z","iopub.status.idle":"2022-03-18T03:33:23.620986Z","shell.execute_reply.started":"2022-03-18T03:33:23.607955Z","shell.execute_reply":"2022-03-18T03:33:23.620018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Price distribution of best selling article","metadata":{}},{"cell_type":"code","source":"# price distribution of best selling article\nsns.set_style(\"darkgrid\")\nfigure, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=top_1_selling_article, x='price', color='xkcd:blue')\n# ax = sns.histplot(data=top_1_selling_article, x='price', bins=100, color='xkcd:blue')\nax.set_xlabel('price')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:23.622938Z","iopub.execute_input":"2022-03-18T03:33:23.623614Z","iopub.status.idle":"2022-03-18T03:33:24.395763Z","shell.execute_reply.started":"2022-03-18T03:33:23.623561Z","shell.execute_reply":"2022-03-18T03:33:24.394460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Price distribution of top 5 selling articles","metadata":{}},{"cell_type":"code","source":"# price distribution of top 5 selling articles\nsns.set_style(\"darkgrid\")\nfor n in range(5):\n    top_n_selling_article = transactions_train[transactions_train['article_id'] == article_sorted_by_sales.index[n]]\n    print(\"[{}] highest price sold = {:.3f}\".format(n, top_n_selling_article['price'].max()))\n    figure, ax = plt.subplots(figsize=(10,5))\n    ax = sns.histplot(data=top_n_selling_article, x='price', color='xkcd:blue')\n#     ax = sns.histplot(data=top_n_selling_article, x='price', bins=50, color='xkcd:blue')\n    ax.set_xlabel('price')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:24.397211Z","iopub.execute_input":"2022-03-18T03:33:24.397483Z","iopub.status.idle":"2022-03-18T03:33:28.972633Z","shell.execute_reply.started":"2022-03-18T03:33:24.397450Z","shell.execute_reply":"2022-03-18T03:33:28.971558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### In the case of top-selling articles, a significant amount of sales is generated at the highest price.","metadata":{}},{"cell_type":"code","source":"article_sorted_by_sales.count()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:28.973974Z","iopub.execute_input":"2022-03-18T03:33:28.974201Z","iopub.status.idle":"2022-03-18T03:33:28.981358Z","shell.execute_reply.started":"2022-03-18T03:33:28.974175Z","shell.execute_reply":"2022-03-18T03:33:28.980442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Price distribution of mid selling articles","metadata":{}},{"cell_type":"code","source":"# price distribution of mid selling articles\nsns.set_style(\"darkgrid\")\nnum_of_articles = article_sorted_by_sales.count()\nfor n in range(int(num_of_articles/2), int(num_of_articles/2)+5):\n    top_n_selling_article = transactions_train[transactions_train['article_id'] == article_sorted_by_sales.index[n]]\n    print(\"[{}] highest price sold = {:.3f}\".format(n, top_n_selling_article['price'].max()))\n    figure, ax = plt.subplots(figsize=(10,5))\n    ax = sns.histplot(data=top_n_selling_article, x='price', color='xkcd:magenta')\n#     ax = sns.histplot(data=top_n_selling_article, x='price', bins=50, color='xkcd:blue')\n    ax.set_xlabel('price')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:28.982746Z","iopub.execute_input":"2022-03-18T03:33:28.983010Z","iopub.status.idle":"2022-03-18T03:33:30.661225Z","shell.execute_reply.started":"2022-03-18T03:33:28.982979Z","shell.execute_reply":"2022-03-18T03:33:30.660406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### In the case of intermediate sales articles, sales are generated at various price points, unlike top-selling products.","metadata":{}},{"cell_type":"markdown","source":"[Contents](#contents)","metadata":{}},{"cell_type":"markdown","source":"<a id=samplesubmissions></a>\n## Sample Submissions","metadata":{}},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/sample_submission.csv')\nsample_submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:30.662243Z","iopub.execute_input":"2022-03-18T03:33:30.663054Z","iopub.status.idle":"2022-03-18T03:33:35.581161Z","shell.execute_reply.started":"2022-03-18T03:33:30.663010Z","shell.execute_reply":"2022-03-18T03:33:35.580147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-03-18T03:33:35.582191Z","iopub.execute_input":"2022-03-18T03:33:35.582905Z","iopub.status.idle":"2022-03-18T03:33:36.638913Z","shell.execute_reply.started":"2022-03-18T03:33:35.582866Z","shell.execute_reply":"2022-03-18T03:33:36.637751Z"},"trusted":true},"execution_count":null,"outputs":[]}]}