{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:24.878511Z","iopub.execute_input":"2022-08-23T18:27:24.879281Z","iopub.status.idle":"2022-08-23T18:27:25.632258Z","shell.execute_reply.started":"2022-08-23T18:27:24.879141Z","shell.execute_reply":"2022-08-23T18:27:25.631298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data information & Task requirement \n* articles.csv - detailed metadata for each article_id available for purchase\n* customers.csv - metadata for each customer_id in dataset\n* transactions_train.csv - the training data, consisting of the purchases each customer for each date, as well as additional information. Duplicate rows correspond to multiple purchases of the same item.\n* Your task is to predict the article_ids each customer will purchase during the 7-day period immediately after the training data period.","metadata":{}},{"cell_type":"markdown","source":"## 1.Import data","metadata":{}},{"cell_type":"code","source":"raw_article =pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/articles.csv')\nraw_customers =pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/customers.csv')","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:25.635005Z","iopub.execute_input":"2022-08-23T18:27:25.635735Z","iopub.status.idle":"2022-08-23T18:27:31.667117Z","shell.execute_reply.started":"2022-08-23T18:27:25.635693Z","shell.execute_reply":"2022-08-23T18:27:31.666142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2. data preprocessing ","metadata":{}},{"cell_type":"code","source":"customer =raw_customers.copy()\ncustomer","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:31.668750Z","iopub.execute_input":"2022-08-23T18:27:31.669130Z","iopub.status.idle":"2022-08-23T18:27:31.814045Z","shell.execute_reply.started":"2022-08-23T18:27:31.669092Z","shell.execute_reply":"2022-08-23T18:27:31.813033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer =customer.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)\ncustomer","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:31.816741Z","iopub.execute_input":"2022-08-23T18:27:31.817131Z","iopub.status.idle":"2022-08-23T18:27:32.151558Z","shell.execute_reply.started":"2022-08-23T18:27:31.817094Z","shell.execute_reply":"2022-08-23T18:27:32.150157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article =raw_article.copy()\narticle =article.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)\narticle","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.153294Z","iopub.execute_input":"2022-08-23T18:27:32.153681Z","iopub.status.idle":"2022-08-23T18:27:32.370740Z","shell.execute_reply.started":"2022-08-23T18:27:32.153645Z","shell.execute_reply":"2022-08-23T18:27:32.369574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1-1 clean customer data","metadata":{}},{"cell_type":"code","source":"customer.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.372522Z","iopub.execute_input":"2022-08-23T18:27:32.372919Z","iopub.status.idle":"2022-08-23T18:27:32.437688Z","shell.execute_reply.started":"2022-08-23T18:27:32.372871Z","shell.execute_reply":"2022-08-23T18:27:32.436605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**> As we can see, age data has outliers (age 99), deep dive into age data**","metadata":{}},{"cell_type":"markdown","source":"> **we can see age group 90s has significantly low numbers than age group 20's **","metadata":{}},{"cell_type":"code","source":"customer['age'].value_counts()/ customer['age'].shape[0] *100","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.439450Z","iopub.execute_input":"2022-08-23T18:27:32.439842Z","iopub.status.idle":"2022-08-23T18:27:32.459117Z","shell.execute_reply.started":"2022-08-23T18:27:32.439804Z","shell.execute_reply":"2022-08-23T18:27:32.458216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"age_mean = customer['age'].mean()\nage_min= customer['age'].min()\nage_max= customer['age'].max()\n\n'average customer age is {}, min customer age is {} max customer age is {}:'.format(age_mean, age_min,age_max)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.460570Z","iopub.execute_input":"2022-08-23T18:27:32.461893Z","iopub.status.idle":"2022-08-23T18:27:32.474339Z","shell.execute_reply.started":"2022-08-23T18:27:32.461858Z","shell.execute_reply":"2022-08-23T18:27:32.473490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":">  we can see percentage of customer age group 90s has significantly low, so we can drop the data","metadata":{}},{"cell_type":"code","source":"customer = customer[customer['age'] < 50]","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.475728Z","iopub.execute_input":"2022-08-23T18:27:32.476082Z","iopub.status.idle":"2022-08-23T18:27:32.513085Z","shell.execute_reply.started":"2022-08-23T18:27:32.476050Z","shell.execute_reply":"2022-08-23T18:27:32.512227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"age_mean = customer['age'].mean()\nage_min= customer['age'].min()\nage_max= customer['age'].max()\n\n'average customer age is {}, min customer age is {} max customer age is {}:'.format(age_mean, age_min,age_max)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.517928Z","iopub.execute_input":"2022-08-23T18:27:32.518699Z","iopub.status.idle":"2022-08-23T18:27:32.529590Z","shell.execute_reply.started":"2022-08-23T18:27:32.518664Z","shell.execute_reply":"2022-08-23T18:27:32.528572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer['age'].value_counts()/ customer['age'].shape[0] *100","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.531309Z","iopub.execute_input":"2022-08-23T18:27:32.531939Z","iopub.status.idle":"2022-08-23T18:27:32.548522Z","shell.execute_reply.started":"2022-08-23T18:27:32.531905Z","shell.execute_reply":"2022-08-23T18:27:32.547367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### As we can see age group 10's has also significant low percentage in total age. so We will drop this age group","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.550572Z","iopub.execute_input":"2022-08-23T18:27:32.551278Z","iopub.status.idle":"2022-08-23T18:27:32.556030Z","shell.execute_reply.started":"2022-08-23T18:27:32.551077Z","shell.execute_reply":"2022-08-23T18:27:32.555124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer = customer.drop(customer[(customer['age'] >= 50) | (customer['age'] <= 20)].index, inplace =False)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.557298Z","iopub.execute_input":"2022-08-23T18:27:32.558258Z","iopub.status.idle":"2022-08-23T18:27:32.642144Z","shell.execute_reply.started":"2022-08-23T18:27:32.558224Z","shell.execute_reply":"2022-08-23T18:27:32.641112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"age_mean = customer['age'].mean()\nage_min= customer['age'].min()\nage_max= customer['age'].max()\n\nprint('average customer age is {}, min customer age is {} max customer age is {}:'.format(age_mean, age_min,age_max))","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.643802Z","iopub.execute_input":"2022-08-23T18:27:32.644182Z","iopub.status.idle":"2022-08-23T18:27:32.654853Z","shell.execute_reply.started":"2022-08-23T18:27:32.644146Z","shell.execute_reply":"2022-08-23T18:27:32.653535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 1-2  Check categorical values","metadata":{}},{"cell_type":"code","source":"customer['club_member_status'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.657196Z","iopub.execute_input":"2022-08-23T18:27:32.657816Z","iopub.status.idle":"2022-08-23T18:27:32.683395Z","shell.execute_reply.started":"2022-08-23T18:27:32.657778Z","shell.execute_reply":"2022-08-23T18:27:32.682218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"member_status = pd.DataFrame(customer['club_member_status'].value_counts()/customer['club_member_status'].shape[0] * 100)\nmember_status","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.685484Z","iopub.execute_input":"2022-08-23T18:27:32.686235Z","iopub.status.idle":"2022-08-23T18:27:32.714579Z","shell.execute_reply.started":"2022-08-23T18:27:32.686198Z","shell.execute_reply":"2022-08-23T18:27:32.713376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### 'Left club' and Pre-create are too small data, so we can drop two groups. \ncustomer = customer[customer['club_member_status'] =='ACTIVE']\ncustomer['club_member_status'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.716154Z","iopub.execute_input":"2022-08-23T18:27:32.717301Z","iopub.status.idle":"2022-08-23T18:27:32.797347Z","shell.execute_reply.started":"2022-08-23T18:27:32.717264Z","shell.execute_reply":"2022-08-23T18:27:32.796331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer['fashion_news_frequency'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.798599Z","iopub.execute_input":"2022-08-23T18:27:32.798943Z","iopub.status.idle":"2022-08-23T18:27:32.826306Z","shell.execute_reply.started":"2022-08-23T18:27:32.798907Z","shell.execute_reply":"2022-08-23T18:27:32.825361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer['fashion_news_frequency'].value_counts()/customer['fashion_news_frequency'].shape[0]*100","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.828065Z","iopub.execute_input":"2022-08-23T18:27:32.828651Z","iopub.status.idle":"2022-08-23T18:27:32.854432Z","shell.execute_reply.started":"2022-08-23T18:27:32.828615Z","shell.execute_reply":"2022-08-23T18:27:32.853360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> #### Since category (Monthly and none) fashion news frequecy are lower than 1% in the dataset, Removed it from it. ","metadata":{}},{"cell_type":"code","source":"customer= customer[customer['fashion_news_frequency'] =='Regularly']\ncustomer['fashion_news_frequency'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.856150Z","iopub.execute_input":"2022-08-23T18:27:32.856532Z","iopub.status.idle":"2022-08-23T18:27:32.935374Z","shell.execute_reply.started":"2022-08-23T18:27:32.856461Z","shell.execute_reply":"2022-08-23T18:27:32.934380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 1-3  Remove unneccessary data columns ","metadata":{}},{"cell_type":"code","source":"customer.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.936633Z","iopub.execute_input":"2022-08-23T18:27:32.937808Z","iopub.status.idle":"2022-08-23T18:27:32.983330Z","shell.execute_reply.started":"2022-08-23T18:27:32.937771Z","shell.execute_reply":"2022-08-23T18:27:32.982444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> ### Since FN and Active status has all same variables, we can drop it + Postal code will not be used for this analysis, we can drop the columns","metadata":{}},{"cell_type":"code","source":"customer = customer.drop(columns = ['FN','Active', 'postal_code'], axis =1 )","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:32.984648Z","iopub.execute_input":"2022-08-23T18:27:32.985233Z","iopub.status.idle":"2022-08-23T18:27:33.015978Z","shell.execute_reply.started":"2022-08-23T18:27:32.985194Z","shell.execute_reply":"2022-08-23T18:27:33.015044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"*For future analysis we won't use 'club_member_status* and 'fashion_news_frequency'columns because the categorical variables are all same, we can drop it and save as new data","metadata":{}},{"cell_type":"code","source":"customer_cleaned = customer.drop(columns = ['club_member_status', 'fashion_news_frequency'], axis =1 )","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.017410Z","iopub.execute_input":"2022-08-23T18:27:33.017858Z","iopub.status.idle":"2022-08-23T18:27:33.030730Z","shell.execute_reply.started":"2022-08-23T18:27:33.017822Z","shell.execute_reply":"2022-08-23T18:27:33.029482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2. Article data preprocessing ","metadata":{}},{"cell_type":"code","source":"article.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.032889Z","iopub.execute_input":"2022-08-23T18:27:33.033440Z","iopub.status.idle":"2022-08-23T18:27:33.112870Z","shell.execute_reply.started":"2022-08-23T18:27:33.033404Z","shell.execute_reply":"2022-08-23T18:27:33.111947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article['product_group_name'].value_counts()/article['product_group_name'].shape[0]*100\n","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.114532Z","iopub.execute_input":"2022-08-23T18:27:33.114888Z","iopub.status.idle":"2022-08-23T18:27:33.131683Z","shell.execute_reply.started":"2022-08-23T18:27:33.114853Z","shell.execute_reply":"2022-08-23T18:27:33.130287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2-1 drop the data ","metadata":{}},{"cell_type":"code","source":"## drop the categories which has less than 1 % in the data\narticle = article.drop(article[(article['product_group_name'] == \"Underwear/nightwear\") | (article['product_group_name'] == 'Cosmetic')| \n                               (article['product_group_name'] == 'Bags')|(article['product_group_name'] == 'Items')|(article['product_group_name'] == 'Furniture')|\n                               (article['product_group_name'] == 'Garment and Shoe care')|(article['product_group_name'] == 'Stationery')|(article['product_group_name'] == 'Unknown')|\n                               (article['product_group_name'] == \"Fun\") | (article['product_group_name'] == 'Interior textile')].index, inplace =False)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.133407Z","iopub.execute_input":"2022-08-23T18:27:33.134118Z","iopub.status.idle":"2022-08-23T18:27:33.232213Z","shell.execute_reply.started":"2022-08-23T18:27:33.134082Z","shell.execute_reply":"2022-08-23T18:27:33.231261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article['product_group_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.233478Z","iopub.execute_input":"2022-08-23T18:27:33.233816Z","iopub.status.idle":"2022-08-23T18:27:33.249420Z","shell.execute_reply.started":"2022-08-23T18:27:33.233779Z","shell.execute_reply":"2022-08-23T18:27:33.248337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Create group for colour group","metadata":{}},{"cell_type":"code","source":"article['colour_group_name'].value_counts()/article['colour_group_name'].shape[0] *100","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.257533Z","iopub.execute_input":"2022-08-23T18:27:33.258535Z","iopub.status.idle":"2022-08-23T18:27:33.276219Z","shell.execute_reply.started":"2022-08-23T18:27:33.258500Z","shell.execute_reply":"2022-08-23T18:27:33.275355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article['colour_group_name'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.277473Z","iopub.execute_input":"2022-08-23T18:27:33.278348Z","iopub.status.idle":"2022-08-23T18:27:33.294637Z","shell.execute_reply.started":"2022-08-23T18:27:33.278287Z","shell.execute_reply":"2022-08-23T18:27:33.293503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yellow = ['Yellow', 'Light Yellow','Other Yellow', 'Dark Yellow']\npink = ['Light Pink','Pink','Dark Pink', 'Other Pink']\nblue = ['Dark Blue', 'Blue', 'Light Blue', 'Other Blue' ]\nwhite = ['White', 'Off White']\nbeige =['Light Beige','Greyish Beige','Beige', 'Dark Beige','Light Beige']\nred =['Red','Dark Red', 'Light Red', 'Other Red']\ngreen = ['Green','Dark Green', 'Light Green', 'Other Green', 'Greenish Khaki']\npurple =['Purple', 'Dark Purple', 'Light Purple','Other Purple']\nturquoise =['Turquoise', 'Other Turquoise', 'Dark Turquoise', 'Other Turquoise' ]\norange = ['Dark Orange', 'Orange','Other Orange' ]\ngold =['Yellowish Brown', 'Bronze/Copper', 'Yellowish Brown','Gold']\ngrey =['Silver','Grey','Dark Grey','Light Grey']\nblack =['Black']","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.296814Z","iopub.execute_input":"2022-08-23T18:27:33.297052Z","iopub.status.idle":"2022-08-23T18:27:33.304988Z","shell.execute_reply.started":"2022-08-23T18:27:33.297029Z","shell.execute_reply":"2022-08-23T18:27:33.303981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def color_group(color):\n    if any(s in color for s in yellow):\n        return 'yellow'\n    elif any(s in color for s in pink):\n        return 'pink'\n    elif any(s in color for s in blue):\n        return 'blue'\n    elif any(s in color for s in white):\n        return 'white'\n    elif any(s in color for s in beige):\n        return 'beige'\n    elif any(s in color for s in red):\n        return 'red'\n    elif any(s in color for s in green):\n        return 'green'\n    elif any(s in color for s in purple):\n        return 'purple'\n    elif any(s in color for s in turquoise):\n        return 'turquoise'\n    elif any(s in color for s in orange):\n        return 'orange'\n    elif any(s in color for s in gold):\n        return 'gold'\n    elif any(s in color for s in grey):\n        return 'grey'\n    elif any(s in color for s in black):\n        return 'black'\n    else:\n        return 'other'\narticle['colour_group_name'] = article['colour_group_name'].apply(color_group)\n","metadata":{"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2022-08-23T18:27:33.306755Z","iopub.execute_input":"2022-08-23T18:27:33.307541Z","iopub.status.idle":"2022-08-23T18:27:33.822095Z","shell.execute_reply.started":"2022-08-23T18:27:33.307508Z","shell.execute_reply":"2022-08-23T18:27:33.820996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article['colour_group_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.823860Z","iopub.execute_input":"2022-08-23T18:27:33.824296Z","iopub.status.idle":"2022-08-23T18:27:33.836301Z","shell.execute_reply.started":"2022-08-23T18:27:33.824257Z","shell.execute_reply":"2022-08-23T18:27:33.835347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Save article data ","metadata":{}},{"cell_type":"code","source":"article.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.837963Z","iopub.execute_input":"2022-08-23T18:27:33.838760Z","iopub.status.idle":"2022-08-23T18:27:33.912312Z","shell.execute_reply.started":"2022-08-23T18:27:33.838722Z","shell.execute_reply":"2022-08-23T18:27:33.911205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_cleaned= article[['article_id','prod_name','product_group_name','colour_group_name']]\narticle_cleaned.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.913664Z","iopub.execute_input":"2022-08-23T18:27:33.914169Z","iopub.status.idle":"2022-08-23T18:27:33.942545Z","shell.execute_reply.started":"2022-08-23T18:27:33.914135Z","shell.execute_reply":"2022-08-23T18:27:33.941458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_cleaned.head(50)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.944180Z","iopub.execute_input":"2022-08-23T18:27:33.944545Z","iopub.status.idle":"2022-08-23T18:27:33.960499Z","shell.execute_reply.started":"2022-08-23T18:27:33.944510Z","shell.execute_reply":"2022-08-23T18:27:33.959558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_cleaned.article_id =article_cleaned.article_id.astype('int32')","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.962427Z","iopub.execute_input":"2022-08-23T18:27:33.962885Z","iopub.status.idle":"2022-08-23T18:27:33.977714Z","shell.execute_reply.started":"2022-08-23T18:27:33.962850Z","shell.execute_reply":"2022-08-23T18:27:33.976217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_cleaned.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.980551Z","iopub.execute_input":"2022-08-23T18:27:33.980855Z","iopub.status.idle":"2022-08-23T18:27:33.994124Z","shell.execute_reply.started":"2022-08-23T18:27:33.980827Z","shell.execute_reply":"2022-08-23T18:27:33.992952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article_cleaned.to_csv('article_cleaned.csv', index= False)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:33.995714Z","iopub.execute_input":"2022-08-23T18:27:33.996550Z","iopub.status.idle":"2022-08-23T18:27:34.189078Z","shell.execute_reply.started":"2022-08-23T18:27:33.996515Z","shell.execute_reply":"2022-08-23T18:27:34.188084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Import Train data and reduce the memory ","metadata":{}},{"cell_type":"markdown","source":"[https://www.kaggle.com/competitions/h-and-m-personalized-fashion-recommendations/discussion/308635](http://)","metadata":{}},{"cell_type":"code","source":"transaction_train_raw =pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\",\n            dtype={\"t_dat\": \"object\", \"customer_id\": 'object', \"article_id\": int, \"price\": float, \"sales_channel_id\": int}\n           )","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:27:34.190654Z","iopub.execute_input":"2022-08-23T18:27:34.191358Z","iopub.status.idle":"2022-08-23T18:28:34.561234Z","shell.execute_reply.started":"2022-08-23T18:27:34.191296Z","shell.execute_reply":"2022-08-23T18:28:34.560278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_train_raw.head(1000)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:28:34.562682Z","iopub.execute_input":"2022-08-23T18:28:34.563242Z","iopub.status.idle":"2022-08-23T18:28:34.580805Z","shell.execute_reply.started":"2022-08-23T18:28:34.563202Z","shell.execute_reply":"2022-08-23T18:28:34.579860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1. remove the unnecessary columns ","metadata":{}},{"cell_type":"code","source":"transaction_df =transaction_train_raw.iloc[:,0:3]\ntransaction_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:28:34.582301Z","iopub.execute_input":"2022-08-23T18:28:34.582950Z","iopub.status.idle":"2022-08-23T18:28:35.347703Z","shell.execute_reply.started":"2022-08-23T18:28:34.582914Z","shell.execute_reply":"2022-08-23T18:28:35.346368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2.  Reduce the memory usage ","metadata":{}},{"cell_type":"code","source":"transaction_df['customer_id'] =\\\n    transaction_df['customer_id'].apply(lambda x: int(x[-16:],16) ).astype('int64')","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:28:35.349304Z","iopub.execute_input":"2022-08-23T18:28:35.349905Z","iopub.status.idle":"2022-08-23T18:28:58.153822Z","shell.execute_reply.started":"2022-08-23T18:28:35.349869Z","shell.execute_reply":"2022-08-23T18:28:58.152704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_df.t_dat = pd.to_datetime(transaction_df.t_dat, format = \"%Y-%m-%d\")\ntransaction_df['article_id'] = transaction_df.article_id.astype('int32')\ntransaction_df['article_id'] = '0' + transaction_df.article_id.astype('str')","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:28:58.155126Z","iopub.execute_input":"2022-08-23T18:28:58.155973Z","iopub.status.idle":"2022-08-23T18:29:23.426717Z","shell.execute_reply.started":"2022-08-23T18:28:58.155934Z","shell.execute_reply":"2022-08-23T18:29:23.425686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:23.428107Z","iopub.execute_input":"2022-08-23T18:29:23.429140Z","iopub.status.idle":"2022-08-23T18:29:23.441245Z","shell.execute_reply.started":"2022-08-23T18:29:23.429100Z","shell.execute_reply":"2022-08-23T18:29:23.440126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_df","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:23.442922Z","iopub.execute_input":"2022-08-23T18:29:23.445053Z","iopub.status.idle":"2022-08-23T18:29:23.460503Z","shell.execute_reply.started":"2022-08-23T18:29:23.445025Z","shell.execute_reply":"2022-08-23T18:29:23.459479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data exploration","metadata":{}},{"cell_type":"code","source":"Season_trend = transaction_df.groupby('t_dat').nunique()['article_id'].reset_index()\nSeason_trend= Season_trend.rename(columns= {'article_id': 'Count'})\nSeason_trend.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:23.462126Z","iopub.execute_input":"2022-08-23T18:29:23.462991Z","iopub.status.idle":"2022-08-23T18:29:45.303776Z","shell.execute_reply.started":"2022-08-23T18:29:23.462953Z","shell.execute_reply":"2022-08-23T18:29:45.302640Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Plot timeseries ","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:45.305751Z","iopub.execute_input":"2022-08-23T18:29:45.306170Z","iopub.status.idle":"2022-08-23T18:29:45.311275Z","shell.execute_reply.started":"2022-08-23T18:29:45.306130Z","shell.execute_reply":"2022-08-23T18:29:45.310109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(Season_trend['t_dat'], Season_trend['Count'])\nplt.xticks(rotation=45)\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:45.313037Z","iopub.execute_input":"2022-08-23T18:29:45.313433Z","iopub.status.idle":"2022-08-23T18:29:45.579747Z","shell.execute_reply.started":"2022-08-23T18:29:45.313397Z","shell.execute_reply":"2022-08-23T18:29:45.578808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Who Buy What? \n\n> ### Since the data is too large, we can see the transaction data in 3 month from last transaction ","metadata":{}},{"cell_type":"code","source":"transaction_df","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:45.581048Z","iopub.execute_input":"2022-08-23T18:29:45.582005Z","iopub.status.idle":"2022-08-23T18:29:45.596607Z","shell.execute_reply.started":"2022-08-23T18:29:45.581966Z","shell.execute_reply":"2022-08-23T18:29:45.595557Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"year_df =transaction_df[transaction_df['t_dat'] > '2020-06-30'].reset_index(drop=True)\nyear_df","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:45.597887Z","iopub.execute_input":"2022-08-23T18:29:45.598390Z","iopub.status.idle":"2022-08-23T18:29:46.012011Z","shell.execute_reply.started":"2022-08-23T18:29:45.598349Z","shell.execute_reply":"2022-08-23T18:29:46.010911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"year_df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.013589Z","iopub.execute_input":"2022-08-23T18:29:46.014089Z","iopub.status.idle":"2022-08-23T18:29:46.026977Z","shell.execute_reply.started":"2022-08-23T18:29:46.014045Z","shell.execute_reply":"2022-08-23T18:29:46.025452Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Get the top 10 most frequently purchased item in last three month ","metadata":{}},{"cell_type":"code","source":"frequently_bought = pd.DataFrame(year_df['article_id'].value_counts().head(10).reset_index())\nfrequently_bought =frequently_bought.rename(columns = {'index':\"article_id\",'article_id':'counts'})","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.029045Z","iopub.execute_input":"2022-08-23T18:29:46.029785Z","iopub.status.idle":"2022-08-23T18:29:46.492581Z","shell.execute_reply.started":"2022-08-23T18:29:46.029745Z","shell.execute_reply":"2022-08-23T18:29:46.491567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"frequently_bought.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.493827Z","iopub.execute_input":"2022-08-23T18:29:46.494817Z","iopub.status.idle":"2022-08-23T18:29:46.505155Z","shell.execute_reply.started":"2022-08-23T18:29:46.494776Z","shell.execute_reply":"2022-08-23T18:29:46.503880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"frequently_bought['article_id'] = frequently_bought['article_id'].astype(int)\narticle_cleaned['article_id'] = article_cleaned['article_id'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.506531Z","iopub.execute_input":"2022-08-23T18:29:46.507506Z","iopub.status.idle":"2022-08-23T18:29:46.516229Z","shell.execute_reply.started":"2022-08-23T18:29:46.507465Z","shell.execute_reply":"2022-08-23T18:29:46.515018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"three_months_purchase = pd.DataFrame(year_df['article_id'].value_counts().reset_index())\nthree_months_purchase =three_months_purchase.rename(columns = {'index':\"article_id\",'article_id':'counts'})","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.517918Z","iopub.execute_input":"2022-08-23T18:29:46.518713Z","iopub.status.idle":"2022-08-23T18:29:46.899675Z","shell.execute_reply.started":"2022-08-23T18:29:46.518624Z","shell.execute_reply":"2022-08-23T18:29:46.898503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"three_months_purchase","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.901299Z","iopub.execute_input":"2022-08-23T18:29:46.902014Z","iopub.status.idle":"2022-08-23T18:29:46.915601Z","shell.execute_reply.started":"2022-08-23T18:29:46.901975Z","shell.execute_reply":"2022-08-23T18:29:46.914240Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merge = frequently_bought.merge(article_cleaned, on ='article_id')","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.917719Z","iopub.execute_input":"2022-08-23T18:29:46.918156Z","iopub.status.idle":"2022-08-23T18:29:46.951140Z","shell.execute_reply.started":"2022-08-23T18:29:46.918117Z","shell.execute_reply":"2022-08-23T18:29:46.950167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"merge","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.952617Z","iopub.execute_input":"2022-08-23T18:29:46.953727Z","iopub.status.idle":"2022-08-23T18:29:46.966762Z","shell.execute_reply.started":"2022-08-23T18:29:46.953697Z","shell.execute_reply":"2022-08-23T18:29:46.965741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"https://www.kaggle.com/code/negoto/h-m-best-selling-items-catalog-like-eda","metadata":{}},{"cell_type":"code","source":"from PIL import Image\ndef show_images(article_ids, cols=1, texts=[], suptitle=''):\n    if isinstance(article_ids, int) or isinstance(article_ids, str):\n        article_ids = [article_ids]\n    rows = (len(article_ids) // cols) + 1\n    plt.figure(figsize=(3 + 3.5 * cols, 3 + 5 * rows))\n    for i, article_id in enumerate(article_ids):\n        article_id = (\"0\" + str(article_id))[-10:]\n        text = '' if len(texts) <= i else ('\\n' + texts[i])\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{article_id}{text}\", fontsize=16)\n        try:\n            image = Image.open(f\"/kaggle/input/h-and-m-personalized-fashion-recommendations/images/{article_id[:3]}/{article_id}.jpg\")\n            plt.imshow(image)\n        except:\n            pass\n    if suptitle != '': plt.suptitle(suptitle, fontsize=36, fontweight='bold')\n    plt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.968230Z","iopub.execute_input":"2022-08-23T18:29:46.970101Z","iopub.status.idle":"2022-08-23T18:29:46.980069Z","shell.execute_reply.started":"2022-08-23T18:29:46.970064Z","shell.execute_reply":"2022-08-23T18:29:46.979095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_images(merge['article_id'])\n","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:46.981917Z","iopub.execute_input":"2022-08-23T18:29:46.982511Z","iopub.status.idle":"2022-08-23T18:29:49.949669Z","shell.execute_reply.started":"2022-08-23T18:29:46.982461Z","shell.execute_reply":"2022-08-23T18:29:49.948590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> In 3 months, Black pants and socks are the most frequently bought items. \n","metadata":{}},{"cell_type":"markdown","source":"### Explore Most frequently bought items by age","metadata":{}},{"cell_type":"markdown","source":"### Top purchased item by age ","metadata":{}},{"cell_type":"code","source":"year_df.info()\n","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:49.950811Z","iopub.execute_input":"2022-08-23T18:29:49.951861Z","iopub.status.idle":"2022-08-23T18:29:49.965042Z","shell.execute_reply.started":"2022-08-23T18:29:49.951823Z","shell.execute_reply":"2022-08-23T18:29:49.963702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_cleaned.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:49.966897Z","iopub.execute_input":"2022-08-23T18:29:49.967470Z","iopub.status.idle":"2022-08-23T18:29:50.017391Z","shell.execute_reply.started":"2022-08-23T18:29:49.967434Z","shell.execute_reply":"2022-08-23T18:29:50.016089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_cleaned['customer_id'] =\\\n    customer_cleaned['customer_id'].apply(lambda x: int(x[-16:],16) ).astype('int64')","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:50.019454Z","iopub.execute_input":"2022-08-23T18:29:50.019923Z","iopub.status.idle":"2022-08-23T18:29:50.260701Z","shell.execute_reply.started":"2022-08-23T18:29:50.019865Z","shell.execute_reply":"2022-08-23T18:29:50.259724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_article = year_df.merge(customer_cleaned, on ='customer_id')","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:50.262031Z","iopub.execute_input":"2022-08-23T18:29:50.262504Z","iopub.status.idle":"2022-08-23T18:29:50.701895Z","shell.execute_reply.started":"2022-08-23T18:29:50.262469Z","shell.execute_reply":"2022-08-23T18:29:50.700862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_article","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:50.703299Z","iopub.execute_input":"2022-08-23T18:29:50.703775Z","iopub.status.idle":"2022-08-23T18:29:50.720657Z","shell.execute_reply.started":"2022-08-23T18:29:50.703733Z","shell.execute_reply":"2022-08-23T18:29:50.719494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_purchase_by_age = customer_article.groupby('age').article_id.count()\n","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:50.722605Z","iopub.execute_input":"2022-08-23T18:29:50.723463Z","iopub.status.idle":"2022-08-23T18:29:50.838539Z","shell.execute_reply.started":"2022-08-23T18:29:50.723425Z","shell.execute_reply":"2022-08-23T18:29:50.837543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_purchase_by_age.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:50.840269Z","iopub.execute_input":"2022-08-23T18:29:50.840699Z","iopub.status.idle":"2022-08-23T18:29:50.854012Z","shell.execute_reply.started":"2022-08-23T18:29:50.840663Z","shell.execute_reply":"2022-08-23T18:29:50.852877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ax = customer_purchase_by_age.plot(kind= 'bar', figsize= (10,7), title ='purchase count by age',grid =True)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:50.855665Z","iopub.execute_input":"2022-08-23T18:29:50.856192Z","iopub.status.idle":"2022-08-23T18:29:51.190352Z","shell.execute_reply.started":"2022-08-23T18:29:50.856157Z","shell.execute_reply":"2022-08-23T18:29:51.189388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> > We can see most age from 21 to 31 is the major customer age range. ","metadata":{}},{"cell_type":"markdown","source":"### In the age range from 20 to 30, which item was most popular? ","metadata":{}},{"cell_type":"code","source":"customer_purchase_by_article = customer_article[customer_article['age'] < 40.0]","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.191688Z","iopub.execute_input":"2022-08-23T18:29:51.192361Z","iopub.status.idle":"2022-08-23T18:29:51.259410Z","shell.execute_reply.started":"2022-08-23T18:29:51.192304Z","shell.execute_reply":"2022-08-23T18:29:51.258477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_purchase_by_article['age_group'] = customer_purchase_by_article['age'].apply(\n    lambda x : '[20, 25)' if x < 26 else '[26,30)' if x < 31 \\\n    else '[31,35)' if x <36 \n    else '[36, 40)' if x < 41 else '[41+]' )","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.261000Z","iopub.execute_input":"2022-08-23T18:29:51.261375Z","iopub.status.idle":"2022-08-23T18:29:51.466722Z","shell.execute_reply.started":"2022-08-23T18:29:51.261338Z","shell.execute_reply":"2022-08-23T18:29:51.465679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer_purchase_by_article","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.468065Z","iopub.execute_input":"2022-08-23T18:29:51.468705Z","iopub.status.idle":"2022-08-23T18:29:51.487388Z","shell.execute_reply.started":"2022-08-23T18:29:51.468667Z","shell.execute_reply":"2022-08-23T18:29:51.486346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"purchase_by_age_group = customer_purchase_by_article.groupby(['age_group', 'article_id']).agg({'article_id' : 'count'}).rename(columns={'article_id':'count','age_group':'age'}).reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.488904Z","iopub.execute_input":"2022-08-23T18:29:51.489799Z","iopub.status.idle":"2022-08-23T18:29:51.907029Z","shell.execute_reply.started":"2022-08-23T18:29:51.489762Z","shell.execute_reply":"2022-08-23T18:29:51.906076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"purchase_by_age_group['count'].mean()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.908618Z","iopub.execute_input":"2022-08-23T18:29:51.908971Z","iopub.status.idle":"2022-08-23T18:29:51.916463Z","shell.execute_reply.started":"2022-08-23T18:29:51.908926Z","shell.execute_reply":"2022-08-23T18:29:51.915378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_purchase_item = purchase_by_age_group[purchase_by_age_group['count'] > 9]","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.918119Z","iopub.execute_input":"2022-08-23T18:29:51.918798Z","iopub.status.idle":"2022-08-23T18:29:51.933056Z","shell.execute_reply.started":"2022-08-23T18:29:51.918763Z","shell.execute_reply":"2022-08-23T18:29:51.932027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_purchase_item.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.935562Z","iopub.execute_input":"2022-08-23T18:29:51.936272Z","iopub.status.idle":"2022-08-23T18:29:51.950676Z","shell.execute_reply.started":"2022-08-23T18:29:51.936237Z","shell.execute_reply":"2022-08-23T18:29:51.949727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_purchase_item['article_id'] =top_purchase_item.article_id.astype('int32')\n","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.952071Z","iopub.execute_input":"2022-08-23T18:29:51.952725Z","iopub.status.idle":"2022-08-23T18:29:51.962922Z","shell.execute_reply.started":"2022-08-23T18:29:51.952691Z","shell.execute_reply":"2022-08-23T18:29:51.961863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_purchase_item","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.964704Z","iopub.execute_input":"2022-08-23T18:29:51.965174Z","iopub.status.idle":"2022-08-23T18:29:51.979977Z","shell.execute_reply.started":"2022-08-23T18:29:51.965133Z","shell.execute_reply":"2022-08-23T18:29:51.978967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_purchase_item_20s = top_purchase_item[top_purchase_item['age_group'] == '[20, 25)'].sort_values(by='count', ascending = False)\ntop_purchase_item_20s.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:51.981674Z","iopub.execute_input":"2022-08-23T18:29:51.982344Z","iopub.status.idle":"2022-08-23T18:29:52.000411Z","shell.execute_reply.started":"2022-08-23T18:29:51.982290Z","shell.execute_reply":"2022-08-23T18:29:51.999559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top_purchase_item.groupby('age_group').count()","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:52.001676Z","iopub.execute_input":"2022-08-23T18:29:52.001975Z","iopub.status.idle":"2022-08-23T18:29:52.018087Z","shell.execute_reply.started":"2022-08-23T18:29:52.001950Z","shell.execute_reply":"2022-08-23T18:29:52.017220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Top 10 items from age group 20- 25","metadata":{}},{"cell_type":"code","source":"top_ten_item = top_purchase_item_20s.head(10)","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:52.020895Z","iopub.execute_input":"2022-08-23T18:29:52.021741Z","iopub.status.idle":"2022-08-23T18:29:52.026605Z","shell.execute_reply.started":"2022-08-23T18:29:52.021708Z","shell.execute_reply":"2022-08-23T18:29:52.025615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_images(top_ten_item['article_id'])\n","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:52.028137Z","iopub.execute_input":"2022-08-23T18:29:52.029403Z","iopub.status.idle":"2022-08-23T18:29:55.425638Z","shell.execute_reply.started":"2022-08-23T18:29:52.029322Z","shell.execute_reply":"2022-08-23T18:29:55.424610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### We can see the most purchased items are basic black pants, jeans, knits, and basic shirts, and socks ","metadata":{"execution":{"iopub.status.busy":"2022-08-23T18:29:55.437932Z","iopub.execute_input":"2022-08-23T18:29:55.440591Z","iopub.status.idle":"2022-08-23T18:29:55.444924Z","shell.execute_reply.started":"2022-08-23T18:29:55.440553Z","shell.execute_reply":"2022-08-23T18:29:55.443893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"------------processing  --------------------------","metadata":{}},{"cell_type":"markdown","source":"# **Conclusion** ","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}