{"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":"raw","source":"!kaggle competitions download -c h-and-m-personalized-fashion-recommendations","metadata":{"execution":{"iopub.status.busy":"2022-03-29T19:42:19.152051Z","iopub.execute_input":"2022-03-29T19:42:19.152424Z","iopub.status.idle":"2022-03-29T19:42:20.308351Z","shell.execute_reply.started":"2022-03-29T19:42:19.152331Z","shell.execute_reply":"2022-03-29T19:42:20.307502Z"}}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nfrom tqdm.notebook import tqdm\nimport tensorflow as tf\nfrom statsmodels.tsa.seasonal import seasonal_decompose\nfrom tensorflow.keras.preprocessing.sequence import TimeseriesGenerator\nfrom sklearn.preprocessing import MinMaxScaler\nimport matplotlib.pyplot as plt\nfrom tensorflow.keras.callbacks import TensorBoard, EarlyStopping","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:15:13.17185Z","iopub.execute_input":"2022-04-25T05:15:13.172401Z","iopub.status.idle":"2022-04-25T05:15:21.144872Z","shell.execute_reply.started":"2022-04-25T05:15:13.172272Z","shell.execute_reply":"2022-04-25T05:15:21.143941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:15:21.146592Z","iopub.execute_input":"2022-04-25T05:15:21.146885Z","iopub.status.idle":"2022-04-25T05:16:30.317293Z","shell.execute_reply.started":"2022-04-25T05:15:21.146844Z","shell.execute_reply":"2022-04-25T05:16:30.307274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/articles.csv')\ncustomers = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/customers.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:30.332071Z","iopub.execute_input":"2022-04-25T05:16:30.337638Z","iopub.status.idle":"2022-04-25T05:16:39.26604Z","shell.execute_reply.started":"2022-04-25T05:16:30.337326Z","shell.execute_reply":"2022-04-25T05:16:39.264928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Article\narticle_id: unique identifier for the article\n\nproduct_code: identifier for the product (7 digits)\n\nprod_name: name of the product\n\nproduct_type_no: identifier for the type of the product\n\nproduct_type_name: name of the type of the product\n\nproduct_group_name: name of the group of the product\n\ngraphical_appearance_no and graphical_appearance: identifier and name of the graphics\n\ncolour_group_code and colour_group_name: name and identifier of the colour\npercieved_colour_value_id, percieved_colour_value_name, perceived_colour_master_id, perceived_colour_master_name : The added color info\n\ndepartment_no, department_name:  A unique identifier of every department of the product and its name\n\nindex_code, index_name:  A unique identifier of every index and its name\n\nindex_group_no, index_group_name: A group of indeces and its name\n\nsection_no, section_name:  A unique identifier of every section and its \nname\n\ngarment_group_no, garment_group_name: : A unique identifier of every garment and its \n\ndetail_desc: description of the product (detailed)\n","metadata":{}},{"cell_type":"code","source":"print(articles.head())","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:39.269255Z","iopub.execute_input":"2022-04-25T05:16:39.269619Z","iopub.status.idle":"2022-04-25T05:16:39.314564Z","shell.execute_reply.started":"2022-04-25T05:16:39.269569Z","shell.execute_reply":"2022-04-25T05:16:39.313184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15, 7))\nax = sns.histplot(data=articles, y='index_name')\nax.set_xlabel('Count by index name')\nax.set_ylabel('Index name')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:39.316223Z","iopub.execute_input":"2022-04-25T05:16:39.317316Z","iopub.status.idle":"2022-04-25T05:16:39.7591Z","shell.execute_reply.started":"2022-04-25T05:16:39.317266Z","shell.execute_reply":"2022-04-25T05:16:39.757815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15, 7))\nax = sns.histplot(data=articles, y='garment_group_name', 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-04-25T05:16:39.760687Z","iopub.execute_input":"2022-04-25T05:16:39.761373Z","iopub.status.idle":"2022-04-25T05:16:40.521808Z","shell.execute_reply.started":"2022-04-25T05:16:39.761326Z","shell.execute_reply":"2022-04-25T05:16:40.521192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15, 7))\nax = sns.histplot(data=articles, y='index_group_name', hue='section_name', multiple=\"stack\")\nax.set_xlabel('count by garment group')\nax.set_ylabel('garment group')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:40.522723Z","iopub.execute_input":"2022-04-25T05:16:40.523459Z","iopub.status.idle":"2022-04-25T05:16:42.667479Z","shell.execute_reply.started":"2022-04-25T05:16:40.523425Z","shell.execute_reply":"2022-04-25T05:16:42.6665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.groupby(['index_group_name', 'index_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:42.668758Z","iopub.execute_input":"2022-04-25T05:16:42.669023Z","iopub.status.idle":"2022-04-25T05:16:42.775021Z","shell.execute_reply.started":"2022-04-25T05:16:42.668994Z","shell.execute_reply":"2022-04-25T05:16:42.774094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.options.display.max_rows = None\narticles.groupby(['product_group_name', 'product_type_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:42.776426Z","iopub.execute_input":"2022-04-25T05:16:42.776651Z","iopub.status.idle":"2022-04-25T05:16:42.8789Z","shell.execute_reply.started":"2022-04-25T05:16:42.776624Z","shell.execute_reply":"2022-04-25T05:16:42.878062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.options.display.max_rows = None\narticles.groupby(['department_name', 'product_group_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:42.880299Z","iopub.execute_input":"2022-04-25T05:16:42.880687Z","iopub.status.idle":"2022-04-25T05:16:42.987674Z","shell.execute_reply.started":"2022-04-25T05:16:42.880652Z","shell.execute_reply":"2022-04-25T05:16:42.986816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in articles.columns:\n    if not 'no' in col and not 'code' in col and not 'id' in col:\n        un_n = articles[col].nunique()\n        print(f'number of unique {col}: {un_n}')","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:42.991697Z","iopub.execute_input":"2022-04-25T05:16:42.99205Z","iopub.status.idle":"2022-04-25T05:16:43.112545Z","shell.execute_reply.started":"2022-04-25T05:16:42.992009Z","shell.execute_reply":"2022-04-25T05:16:43.111571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## customers\n\ncustomer_id: unique identifier for the customer\nFN: ? (1 or NA)\nActive: ? (1 or NA)\nclub_member_status: if they are in the H&M club (ACTIVE or PRE_create, etc)\nfashion_news_frequency: maybe how often does H&M send the customers news\nAge: age of the customer\npostal_code: (Hashed)\n\n","metadata":{}},{"cell_type":"code","source":" # All the customers are unique\n    customers['customer_id'].nunique()- customers['customer_id'].count()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:43.113585Z","iopub.execute_input":"2022-04-25T05:16:43.11379Z","iopub.status.idle":"2022-04-25T05:16:43.120364Z","shell.execute_reply.started":"2022-04-25T05:16:43.113764Z","shell.execute_reply":"2022-04-25T05:16:43.119024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customers, x='age', bins=50)\nax.set_xlabel('Distribution of the customers age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:19:01.61794Z","iopub.execute_input":"2022-04-25T05:19:01.618368Z","iopub.status.idle":"2022-04-25T05:19:02.142931Z","shell.execute_reply.started":"2022-04-25T05:19:01.618317Z","shell.execute_reply":"2022-04-25T05:19:02.141867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_postal = customers.groupby('postal_code', as_index=False).count().sort_values('customer_id', ascending=False)\ndata_postal.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:19:08.487625Z","iopub.execute_input":"2022-04-25T05:19:08.487942Z","iopub.status.idle":"2022-04-25T05:19:10.337418Z","shell.execute_reply.started":"2022-04-25T05:19:08.487907Z","shell.execute_reply":"2022-04-25T05:19:10.336494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = sns.histplot(data=customers, x='fashion_news_frequency', color='orange')\nax.set_xlabel('Distribution of fashion_news_frequency')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:19:16.857151Z","iopub.execute_input":"2022-04-25T05:19:16.857425Z","iopub.status.idle":"2022-04-25T05:19:18.332537Z","shell.execute_reply.started":"2022-04-25T05:19:16.857394Z","shell.execute_reply":"2022-04-25T05:19:18.331608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = sns.histplot(data=customers, x='club_member_status', color='orange')\nax.set_xlabel('Distribution of club member status')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:19:18.398969Z","iopub.execute_input":"2022-04-25T05:19:18.399244Z","iopub.status.idle":"2022-04-25T05:19:19.463686Z","shell.execute_reply.started":"2022-04-25T05:19:18.399215Z","shell.execute_reply":"2022-04-25T05:19:19.462612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"number of FN\", len(customers[customers['FN'] ==1 ]))","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:19:25.413363Z","iopub.execute_input":"2022-04-25T05:19:25.413839Z","iopub.status.idle":"2022-04-25T05:19:25.4932Z","shell.execute_reply.started":"2022-04-25T05:19:25.413803Z","shell.execute_reply":"2022-04-25T05:19:25.49224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"number of active customers\", len(customers[customers['Active'] ==1 ]))","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:19:57.669901Z","iopub.execute_input":"2022-04-25T05:19:57.670351Z","iopub.status.idle":"2022-04-25T05:19:57.750343Z","shell.execute_reply.started":"2022-04-25T05:19:57.670302Z","shell.execute_reply":"2022-04-25T05:19:57.749452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## transaction_train\nt_dat: the dat of the transaction\n\ncustomer_id: id of customers\n\narticle_id: id of the articles\n\nprice: price of the purchase\n\nsales_channel_id: 1 or 2","metadata":{}},{"cell_type":"code","source":"train = transactions_train\nprint(\"number of transactions:\" , len(train['customer_id']))","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:20:05.313117Z","iopub.execute_input":"2022-04-25T05:20:05.313679Z","iopub.status.idle":"2022-04-25T05:20:05.318581Z","shell.execute_reply.started":"2022-04-25T05:20:05.313642Z","shell.execute_reply":"2022-04-25T05:20:05.317941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:20:07.281664Z","iopub.execute_input":"2022-04-25T05:20:07.281959Z","iopub.status.idle":"2022-04-25T05:20:07.296226Z","shell.execute_reply.started":"2022-04-25T05:20:07.281924Z","shell.execute_reply":"2022-04-25T05:20:07.295249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_count_per_customer = train.groupby('customer_id').count()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:20:14.251594Z","iopub.execute_input":"2022-04-25T05:20:14.251907Z","iopub.status.idle":"2022-04-25T05:20:29.586726Z","shell.execute_reply.started":"2022-04-25T05:20:14.251875Z","shell.execute_reply":"2022-04-25T05:20:29.585834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_count_per_customer.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:20:29.588508Z","iopub.execute_input":"2022-04-25T05:20:29.588846Z","iopub.status.idle":"2022-04-25T05:20:29.599996Z","shell.execute_reply.started":"2022-04-25T05:20:29.5888Z","shell.execute_reply":"2022-04-25T05:20:29.599021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_count_per_customer.sort_values(by='price', ascending=False)['price'][:10]","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:20:29.601554Z","iopub.execute_input":"2022-04-25T05:20:29.601954Z","iopub.status.idle":"2022-04-25T05:20:30.225312Z","shell.execute_reply.started":"2022-04-25T05:20:29.601912Z","shell.execute_reply":"2022-04-25T05:20:30.224426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_count_per_customer.mean()\n#there is an average of 23.334 transactions per customer","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:20:30.482416Z","iopub.execute_input":"2022-04-25T05:20:30.484081Z","iopub.status.idle":"2022-04-25T05:20:30.500434Z","shell.execute_reply.started":"2022-04-25T05:20:30.484044Z","shell.execute_reply":"2022-04-25T05:20:30.499649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_count_per_customer.describe()['price']","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:20:30.227169Z","iopub.execute_input":"2022-04-25T05:20:30.227417Z","iopub.status.idle":"2022-04-25T05:20:30.462206Z","shell.execute_reply.started":"2022-04-25T05:20:30.227386Z","shell.execute_reply":"2022-04-25T05:20:30.461229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"number of people who made zero transactions:\",len(transactions_count_per_customer[transactions_count_per_customer['article_id'] == 0 ]))","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:21:03.634802Z","iopub.execute_input":"2022-04-25T05:21:03.635133Z","iopub.status.idle":"2022-04-25T05:21:03.64313Z","shell.execute_reply.started":"2022-04-25T05:21:03.6351Z","shell.execute_reply":"2022-04-25T05:21:03.642279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"number of people who made more than 40 transactions:\",len(transactions_count_per_customer[transactions_count_per_customer['article_id'] > 40 ]))","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:22:11.567914Z","iopub.execute_input":"2022-04-25T05:22:11.568896Z","iopub.status.idle":"2022-04-25T05:22:11.610424Z","shell.execute_reply.started":"2022-04-25T05:22:11.568828Z","shell.execute_reply":"2022-04-25T05:22:11.609583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"people_with_less_than_40transactions = transactions_count_per_customer[transactions_count_per_customer['article_id'] > 40 ]","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:23:08.668704Z","iopub.execute_input":"2022-04-25T05:23:08.669513Z","iopub.status.idle":"2022-04-25T05:23:08.705357Z","shell.execute_reply.started":"2022-04-25T05:23:08.669472Z","shell.execute_reply":"2022-04-25T05:23:08.704448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(people_with_less_than_40transactions).head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:23:47.573473Z","iopub.execute_input":"2022-04-25T05:23:47.574308Z","iopub.status.idle":"2022-04-25T05:23:47.586513Z","shell.execute_reply.started":"2022-04-25T05:23:47.574253Z","shell.execute_reply":"2022-04-25T05:23:47.585563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(people_with_less_than_40transactions)","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:33:50.587269Z","iopub.execute_input":"2022-04-25T05:33:50.587728Z","iopub.status.idle":"2022-04-25T05:33:50.594661Z","shell.execute_reply.started":"2022-04-25T05:33:50.58768Z","shell.execute_reply":"2022-04-25T05:33:50.593741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"people_with_less_than_40transactions= people_with_less_than_40transactions[people_with_less_than_40transactions['customer_id']]","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:25:23.233824Z","iopub.execute_input":"2022-04-25T05:25:23.234599Z","iopub.status.idle":"2022-04-25T05:25:23.339337Z","shell.execute_reply.started":"2022-04-25T05:25:23.234513Z","shell.execute_reply":"2022-04-25T05:25:23.338316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"people_with_less_than_40transactions = people_with_less_than_40transactions.reset_index(drop= False)","metadata":{"execution":{"iopub.status.busy":"2022-04-25T06:00:10.47351Z","iopub.execute_input":"2022-04-25T06:00:10.473891Z","iopub.status.idle":"2022-04-25T06:00:10.526896Z","shell.execute_reply.started":"2022-04-25T06:00:10.473847Z","shell.execute_reply":"2022-04-25T06:00:10.525927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"people_with_less_than_40transactions.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T06:00:20.636652Z","iopub.execute_input":"2022-04-25T06:00:20.636977Z","iopub.status.idle":"2022-04-25T06:00:20.648816Z","shell.execute_reply.started":"2022-04-25T06:00:20.636939Z","shell.execute_reply":"2022-04-25T06:00:20.647933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"people_with_less_than_40transactions.to_csv(f'Count40.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-04-25T06:00:30.081942Z","iopub.execute_input":"2022-04-25T06:00:30.082835Z","iopub.status.idle":"2022-04-25T06:00:30.742426Z","shell.execute_reply.started":"2022-04-25T06:00:30.08275Z","shell.execute_reply":"2022-04-25T06:00:30.74178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = sns.boxplot(data=train, x='price', color='orange')\nax.set_xlabel('Price outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:43.145824Z","iopub.status.idle":"2022-04-25T05:16:43.146368Z","shell.execute_reply.started":"2022-04-25T05:16:43.146183Z","shell.execute_reply":"2022-04-25T05:16:43.146203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:43.147463Z","iopub.status.idle":"2022-04-25T05:16:43.147788Z","shell.execute_reply.started":"2022-04-25T05:16:43.147632Z","shell.execute_reply":"2022-04-25T05:16:43.147649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge = articles[['article_id', 'prod_name', 'product_type_name', 'product_group_name', 'graphical_appearance_no', 'index_group_name', 'garment_group_name', 'index_name', 'colour_group_name', 'department_name']]","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:43.149099Z","iopub.status.idle":"2022-04-25T05:16:43.1494Z","shell.execute_reply.started":"2022-04-25T05:16:43.149248Z","shell.execute_reply":"2022-04-25T05:16:43.149263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge = train[['customer_id', 'article_id', 'price', 't_dat']].merge(articles_for_merge, on='article_id', how='left')","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:43.150606Z","iopub.status.idle":"2022-04-25T05:16:43.150889Z","shell.execute_reply.started":"2022-04-25T05:16:43.150747Z","shell.execute_reply":"2022-04-25T05:16:43.150762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(25,18))\nax = sns.boxplot(data=articles_for_merge, x='price', y='product_group_name')\nax.set_xlabel('Price outliers', fontsize=22)\nax.set_ylabel('Index names', fontsize=22)\nax.xaxis.set_tick_params(labelsize=22)\nax.yaxis.set_tick_params(labelsize=22)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:43.15186Z","iopub.status.idle":"2022-04-25T05:16:43.152134Z","shell.execute_reply.started":"2022-04-25T05:16:43.15199Z","shell.execute_reply":"2022-04-25T05:16:43.152006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(25,18))\n_ = articles_for_merge[articles_for_merge['product_group_name'] == 'Accessories']\nax = sns.boxplot(data=_, x='price', y='product_type_name')\nax.set_xlabel('Price outliers', fontsize=22)\nax.set_ylabel('Index names', fontsize=22)\nax.xaxis.set_tick_params(labelsize=22)\nax.yaxis.set_tick_params(labelsize=22)\ndel _\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:43.153298Z","iopub.status.idle":"2022-04-25T05:16:43.153629Z","shell.execute_reply.started":"2022-04-25T05:16:43.153445Z","shell.execute_reply":"2022-04-25T05:16:43.153461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_index = articles_for_merge[['index_name', 'price']].groupby('index_name').mean()\nsns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(10,5))\nax = sns.barplot(x=articles_index.price, y=articles_index.index, color='orange', alpha=0.8)\nax.set_xlabel('Price by index')\nax.set_ylabel('Index')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-25T05:16:43.154654Z","iopub.status.idle":"2022-04-25T05:16:43.154931Z","shell.execute_reply.started":"2022-04-25T05:16:43.154787Z","shell.execute_reply":"2022-04-25T05:16:43.154803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_index = articles_for_merge[['product_group_name', 'price']].groupby('product_group_name').mean()\nsns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(10,5))\nax = sns.barplot(x=articles_index.price, y=articles_index.index, color='orange', alpha=0.8)\nax.set_xlabel('Price by product group')\nax.set_ylabel('Product group')\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Extra information\n1. What will the purchases most likely will be?\n2. Dividing the data based on season\n3. Dividing the data based on time","metadata":{}},{"cell_type":"code","source":"train['t_dat']= pd.to_datetime(train['t_dat'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"convertlabeldict = {12: 'Winter',\n                    1: 'Winter', \n                    2:'Winter', \n                    3:'Spring', \n                    4:'Spring', \n                    5:'Spring',\n                    5:'Spring',\n                    6: 'Summer',\n                    7: 'Summer',\n                    8: 'Summer',\n                    9: 'Summer',\n                    10: 'Fall',\n                    11: 'Fall',\n                   }","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import calendar\nimport datetime as dt\nmonth = (train['t_dat'].dt.month)\ntrain['season'] = month.map(convertlabeldict)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15, 7))\nax = sns.histplot(data=train, x='season', color='orange')\nax.set_xlabel('Distribution of the number of purchases based on season')\nplt.show()\n\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge = articles[['article_id', 'prod_name', 'product_type_name', 'product_group_name', 'graphical_appearance_no', 'index_group_name', 'garment_group_name', 'index_name', 'colour_group_name', 'department_name']]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge = train[['customer_id', 'article_id', 'price', 't_dat']].merge(articles_for_merge, on='article_id', how='left')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_for_merge.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15, 7))\nax = sns.histplot(data=train, x='season', color='orange')\nax.set_xlabel('Distribution of the number of purchases based on season')\nplt.show()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"same_prod = 0\nsame_product_type = 0\nsame_product_group = 0\ngraphical_appearance_no = 0\nsame_index = 0\nsame_index_group = 0\nsame_colour_group_name = 0\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}