{"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":"<div style=\"color:white;\n           display:fill;\n           border-radius:5px;\n           background-color:#5642C5;\n           font-size:110%;\n           font-family:Verdana;\n           letter-spacing:0.5px\">\n\n<h1 style=\"padding: 10px;\n              color:white;\">\n\n              H&M Data Visualization\n</h1>\n</div>","metadata":{"papermill":{"duration":0.031593,"end_time":"2022-02-11T16:45:06.299901","exception":false,"start_time":"2022-02-11T16:45:06.268308","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"<h1 style=\"background-color:blue;>If you find this notebook helpful please upvote it</h1>","metadata":{"execution":{"iopub.status.busy":"2022-02-14T01:05:22.171253Z","iopub.execute_input":"2022-02-14T01:05:22.171838Z","iopub.status.idle":"2022-02-14T01:05:22.176818Z","shell.execute_reply.started":"2022-02-14T01:05:22.171804Z","shell.execute_reply":"2022-02-14T01:05:22.175764Z"}}},{"cell_type":"markdown","source":"<h1 style=\"color:blue\">If you find this notebook helpful please upvote it</h1>","metadata":{}},{"cell_type":"markdown","source":"***","metadata":{"papermill":{"duration":0.017781,"end_time":"2022-02-11T16:45:06.339116","exception":false,"start_time":"2022-02-11T16:45:06.321335","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"<h4 style=\"color:purple;\">In this competitions H&M wants you to build a personalize fashion recommendation system because they have huge number of products on their online platform But with too many choices, customers might not quickly find what interests them or what they are looking for, and ultimately, they might not make a purchase. To enhance the shopping experience.</h4>","metadata":{"papermill":{"duration":0.017719,"end_time":"2022-02-11T16:45:06.374875","exception":false,"start_time":"2022-02-11T16:45:06.357156","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"***","metadata":{"papermill":{"duration":0.017724,"end_time":"2022-02-11T16:45:06.410607","exception":false,"start_time":"2022-02-11T16:45:06.392883","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# Dataset","metadata":{"papermill":{"duration":0.02973,"end_time":"2022-02-11T16:45:06.468211","exception":false,"start_time":"2022-02-11T16:45:06.438481","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"<ol style=\"color:purple;\"><li><h4>images/ - a folder of images corresponding to each article_id; images are placed in subfolders starting with the first three digits of the article_id; note, not all article_id values have a corresponding image.</h4></li>\n    <li><h4>articles.csv - detailed metadata for each article_id available for purchase</h4></li>\n    <li><h4>customers.csv - metadata for each customer_id in dataset</h4></li>\n    <li><h4>sample_submission.csv - a sample submission file in the correct format</h4></li>\n<li><h4>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. Your task is to predict the article_ids each customer will purchase during the 7-day period immediately after the training data period.</h4></li><ol>","metadata":{"papermill":{"duration":0.020996,"end_time":"2022-02-11T16:45:06.51809","exception":false,"start_time":"2022-02-11T16:45:06.497094","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"***","metadata":{"papermill":{"duration":0.018489,"end_time":"2022-02-11T16:45:06.554545","exception":false,"start_time":"2022-02-11T16:45:06.536056","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# import necessary libraries\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns \nimport os\nimport numpy as np\nimport cv2\nimport warnings\nimport missingno as msno\nwarnings.filterwarnings('ignore')\n\npd.set_option('display.max_rows', None)\npd.set_option('display.max_columns', None)\npd.set_option('float_format', '{:f}'.format)","metadata":{"papermill":{"duration":1.120502,"end_time":"2022-02-11T16:45:07.693682","exception":false,"start_time":"2022-02-11T16:45:06.57318","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:24:05.007301Z","iopub.execute_input":"2022-02-17T00:24:05.007905Z","iopub.status.idle":"2022-02-17T00:24:06.406120Z","shell.execute_reply.started":"2022-02-17T00:24:05.007791Z","shell.execute_reply":"2022-02-17T00:24:06.405213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMG_DIR=\"../input/h-and-m-personalized-fashion-recommendations/images\"","metadata":{"papermill":{"duration":0.02434,"end_time":"2022-02-11T16:45:07.738151","exception":false,"start_time":"2022-02-11T16:45:07.713811","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:24:06.407993Z","iopub.execute_input":"2022-02-17T00:24:06.408293Z","iopub.status.idle":"2022-02-17T00:24:06.412678Z","shell.execute_reply.started":"2022-02-17T00:24:06.408252Z","shell.execute_reply":"2022-02-17T00:24:06.411901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Reading all the csv files\narticles=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\")\ntransactions=pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")\nsample_submission=pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/sample_submission.csv\")","metadata":{"papermill":{"duration":70.799048,"end_time":"2022-02-11T16:46:18.555032","exception":false,"start_time":"2022-02-11T16:45:07.755984","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:24:06.413902Z","iopub.execute_input":"2022-02-17T00:24:06.414538Z","iopub.status.idle":"2022-02-17T00:25:22.034757Z","shell.execute_reply.started":"2022-02-17T00:24:06.414495Z","shell.execute_reply":"2022-02-17T00:25:22.033987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h4 style=\"color:blue;\">Let's display first few rows of all the dataframes</h4>","metadata":{"papermill":{"duration":0.018109,"end_time":"2022-02-11T16:46:18.591494","exception":false,"start_time":"2022-02-11T16:46:18.573385","status":"completed"},"tags":[]}},{"cell_type":"code","source":"articles.head(2)","metadata":{"papermill":{"duration":0.057412,"end_time":"2022-02-11T16:46:18.667339","exception":false,"start_time":"2022-02-11T16:46:18.609927","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:22.036868Z","iopub.execute_input":"2022-02-17T00:25:22.037215Z","iopub.status.idle":"2022-02-17T00:25:22.067454Z","shell.execute_reply.started":"2022-02-17T00:25:22.037170Z","shell.execute_reply":"2022-02-17T00:25:22.066638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head(2)","metadata":{"papermill":{"duration":0.032907,"end_time":"2022-02-11T16:46:18.719939","exception":false,"start_time":"2022-02-11T16:46:18.687032","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:22.069595Z","iopub.execute_input":"2022-02-17T00:25:22.069901Z","iopub.status.idle":"2022-02-17T00:25:22.080476Z","shell.execute_reply.started":"2022-02-17T00:25:22.069867Z","shell.execute_reply":"2022-02-17T00:25:22.079895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.head(2)","metadata":{"papermill":{"duration":0.031741,"end_time":"2022-02-11T16:46:18.770718","exception":false,"start_time":"2022-02-11T16:46:18.738977","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:22.090271Z","iopub.execute_input":"2022-02-17T00:25:22.090480Z","iopub.status.idle":"2022-02-17T00:25:22.100714Z","shell.execute_reply.started":"2022-02-17T00:25:22.090453Z","shell.execute_reply":"2022-02-17T00:25:22.099918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:28:31.578280Z","iopub.execute_input":"2022-02-17T00:28:31.578541Z","iopub.status.idle":"2022-02-17T00:28:31.587598Z","shell.execute_reply.started":"2022-02-17T00:28:31.578511Z","shell.execute_reply":"2022-02-17T00:28:31.586922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h1 style=\"color:purple;\">Data Visualization</h1>","metadata":{}},{"cell_type":"code","source":"# Let's find out the shapes of all three dataframes\nshape=pd.DataFrame({\"Row\":[articles.shape[0],customers.shape[0],transactions.shape[0]],\n             \"Column\":[articles.shape[1],customers.shape[1],transactions.shape[1]]},index=['articles',\n                                                                                          'customers','transactions'])\ngreen = [{'selector': 'th', 'props': 'background-color: green'}]\nred = [{'selector': 'th', 'props': 'background-color: red'}]\nshape.style.set_table_styles({\"articles\": green, \"customers\": red, \"transactions\": green}, axis=1)","metadata":{"papermill":{"duration":0.084325,"end_time":"2022-02-11T16:46:18.874699","exception":false,"start_time":"2022-02-11T16:46:18.790374","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:22.102250Z","iopub.execute_input":"2022-02-17T00:25:22.102543Z","iopub.status.idle":"2022-02-17T00:25:22.182904Z","shell.execute_reply.started":"2022-02-17T00:25:22.102482Z","shell.execute_reply":"2022-02-17T00:25:22.182126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h3 style=\"color:purple;\">Visualization of missing values</h3>","metadata":{}},{"cell_type":"code","source":"# Missing values in articles dataframe\nmsno.bar(articles,sort='ascending',color='#7209b7',figsize=(20,10),fontsize=14)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:22.184210Z","iopub.execute_input":"2022-02-17T00:25:22.184426Z","iopub.status.idle":"2022-02-17T00:25:25.256043Z","shell.execute_reply.started":"2022-02-17T00:25:22.184399Z","shell.execute_reply":"2022-02-17T00:25:25.255232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### detail_desc column has very few missing values","metadata":{}},{"cell_type":"code","source":"# Missing values in customers dataframe\nmsno.bar(customers,color='#f72585',sort='ascending',figsize=(20,10),fontsize=14)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:25.257585Z","iopub.execute_input":"2022-02-17T00:25:25.258102Z","iopub.status.idle":"2022-02-17T00:25:27.234897Z","shell.execute_reply.started":"2022-02-17T00:25:25.258060Z","shell.execute_reply":"2022-02-17T00:25:27.234362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### In Active and FN column of customers dataset has more than 60% null values  ","metadata":{}},{"cell_type":"code","source":"# Missing values in transactions dataframe\nmsno.bar(transactions,color='#4895ef',sort='ascending',figsize=(20,10),fontsize=14)","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:27.235846Z","iopub.execute_input":"2022-02-17T00:25:27.236208Z","iopub.status.idle":"2022-02-17T00:25:42.188378Z","shell.execute_reply.started":"2022-02-17T00:25:27.236165Z","shell.execute_reply":"2022-02-17T00:25:42.187620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Transactions dataset does not have any null value as all","metadata":{}},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:42.191637Z","iopub.execute_input":"2022-02-17T00:25:42.191853Z","iopub.status.idle":"2022-02-17T00:25:42.216370Z","shell.execute_reply.started":"2022-02-17T00:25:42.191825Z","shell.execute_reply":"2022-02-17T00:25:42.215552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols=['prod_name','product_type_name','product_group_name','graphical_appearance_name',\n      'colour_group_name','department_name','index_name','section_name','garment_group_name']\nfor col in cols:\n    plt.figure(figsize=(10,10))\n    sns.countplot(y=col,data=articles,order=articles[col].value_counts().index[:10])\n    #plt.title(\"Product Group Name\",font='serif',size=20,color=\"purple\")\n    plt.xlabel(\"Count\",size=20,color=\"purple\")\n    plt.ylabel(col,size=20,color=\"purple\")\n    plt.xticks(size=16)\n    plt.yticks(size=16)\n    plt.tight_layout()\n    plt.show()\n    ","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:42.217488Z","iopub.execute_input":"2022-02-17T00:25:42.217678Z","iopub.status.idle":"2022-02-17T00:25:46.043067Z","shell.execute_reply.started":"2022-02-17T00:25:42.217654Z","shell.execute_reply":"2022-02-17T00:25:46.042170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Top 10 most frequently appeared items in their respective columns. ","metadata":{}},{"cell_type":"code","source":"# First two digits of article_id showing the directroy number, So i am creating a new column\n# by taking these two digits it will help us to create the paths of images while image visualization.\n\narticles['dir'] = articles.article_id.astype(str).str[:2].astype(int)","metadata":{"papermill":{"duration":0.186569,"end_time":"2022-02-11T16:46:19.690413","exception":false,"start_time":"2022-02-11T16:46:19.503844","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:46.044415Z","iopub.execute_input":"2022-02-17T00:25:46.044621Z","iopub.status.idle":"2022-02-17T00:25:46.234936Z","shell.execute_reply.started":"2022-02-17T00:25:46.044595Z","shell.execute_reply":"2022-02-17T00:25:46.234317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head()","metadata":{"papermill":{"duration":0.044699,"end_time":"2022-02-11T16:46:19.756729","exception":false,"start_time":"2022-02-11T16:46:19.71203","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:46.236023Z","iopub.execute_input":"2022-02-17T00:25:46.236678Z","iopub.status.idle":"2022-02-17T00:25:46.258808Z","shell.execute_reply.started":"2022-02-17T00:25:46.236643Z","shell.execute_reply":"2022-02-17T00:25:46.257936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(articles.groupby('product_group_name').count()['article_id']).plot.bar(figsize=(10,8))\nplt.xticks(size=14)\nplt.yticks(size=14)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:46.259958Z","iopub.execute_input":"2022-02-17T00:25:46.260182Z","iopub.status.idle":"2022-02-17T00:25:46.737119Z","shell.execute_reply.started":"2022-02-17T00:25:46.260155Z","shell.execute_reply":"2022-02-17T00:25:46.736564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Garment Upper body, Garment Lower body, Garment Full body have maximum number of articles.","metadata":{}},{"cell_type":"code","source":"(articles.groupby('index_name').count()['article_id']).plot.bar(figsize=(10,8))\nplt.xticks(size=14)\nplt.yticks(size=14)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:46.737995Z","iopub.execute_input":"2022-02-17T00:25:46.738496Z","iopub.status.idle":"2022-02-17T00:25:47.136182Z","shell.execute_reply.started":"2022-02-17T00:25:46.738464Z","shell.execute_reply":"2022-02-17T00:25:47.135270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(articles.groupby('garment_group_name').count()['article_id']).plot.bar(figsize=(10,8))\nplt.xticks(size=14)\nplt.yticks(size=14)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:47.137207Z","iopub.execute_input":"2022-02-17T00:25:47.137414Z","iopub.status.idle":"2022-02-17T00:25:47.582603Z","shell.execute_reply.started":"2022-02-17T00:25:47.137388Z","shell.execute_reply":"2022-02-17T00:25:47.581850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Jersey Fancy and Accessories have by far the most number of articles","metadata":{}},{"cell_type":"code","source":"(articles.groupby('section_name').count()['article_id']).plot.bar(figsize=(15,8))\nplt.xticks(size=14)\nplt.yticks(size=14)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:47.583767Z","iopub.execute_input":"2022-02-17T00:25:47.584181Z","iopub.status.idle":"2022-02-17T00:25:48.621436Z","shell.execute_reply.started":"2022-02-17T00:25:47.584151Z","shell.execute_reply":"2022-02-17T00:25:48.620631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Womens Everyday collection and Divided collection appeared most number of time in articles","metadata":{}},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:48.622669Z","iopub.execute_input":"2022-02-17T00:25:48.622877Z","iopub.status.idle":"2022-02-17T00:25:48.642796Z","shell.execute_reply.started":"2022-02-17T00:25:48.622852Z","shell.execute_reply":"2022-02-17T00:25:48.642019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.groupby(['product_group_name','index_name']).count()['article_id']","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:48.643998Z","iopub.execute_input":"2022-02-17T00:25:48.644196Z","iopub.status.idle":"2022-02-17T00:25:48.832048Z","shell.execute_reply.started":"2022-02-17T00:25:48.644170Z","shell.execute_reply":"2022-02-17T00:25:48.831186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Ladieswear has maximum number of articles followed by Divided and Menswear","metadata":{}},{"cell_type":"markdown","source":"<h3 style=\"color:purple\">article_id from the articles dataset is same as image id from the image folder\nHere i am trying to access the article_id corresponding to the particular product_group_name for instance article_id corresponding to the shoes product_group_name and trying to visualiza them.</h3>","metadata":{"papermill":{"duration":0.021824,"end_time":"2022-02-11T16:46:19.800637","exception":false,"start_time":"2022-02-11T16:46:19.778813","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# Get article_id corresponding to the particular product group name\ndef get_article_id(df,group_name):\n    article_id=df[df['product_group_name']==group_name]\n    article_id['article_id']=\"0\"+article_id['article_id'].astype(str)\n    article_id['dir']=\"0\"+article_id['dir'].astype(str)\n    return article_id[['article_id','dir']].reset_index(drop=True)\n\n\n# Read images from fetched articles ids and store the array into the empty list\ndef read_img(data):\n    li=[]\n    for i in range(10):\n        arti=data['article_id'][i]\n        di=data['dir'][i]\n        im=cv2.imread(\"../input/h-and-m-personalized-fashion-recommendations/images/\"+di+\"/\"+arti+\".jpg\")\n        im=cv2.resize(im,(224,224),fx=0,fy=0, interpolation = cv2.INTER_CUBIC)\n        li.append(im)\n    return li\n\n# Display images which are present in empty list in array form\ndef show_img(data):\n    f, axarr = plt.subplots(1,5,figsize=(15,10)) \n    axarr[0].imshow(data[0])\n    axarr[1].imshow(data[1])\n    axarr[2].imshow(data[2])\n    axarr[3].imshow(data[3])\n    axarr[4].imshow(data[4])\n    f.tight_layout()\n    \ndef call(df,group_name):\n    _id=get_article_id(df,group_name)\n    img=read_img(_id)\n    display_img=show_img(img)\n    return display_img\n\n\n\n    ","metadata":{"papermill":{"duration":0.036541,"end_time":"2022-02-11T16:46:19.859019","exception":false,"start_time":"2022-02-11T16:46:19.822478","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:48.833202Z","iopub.execute_input":"2022-02-17T00:25:48.833423Z","iopub.status.idle":"2022-02-17T00:25:48.844434Z","shell.execute_reply.started":"2022-02-17T00:25:48.833396Z","shell.execute_reply":"2022-02-17T00:25:48.843577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Garment Lower body product group name\ncall(articles,\"Garment Lower body\")","metadata":{"papermill":{"duration":1.062334,"end_time":"2022-02-11T16:46:20.943361","exception":false,"start_time":"2022-02-11T16:46:19.881027","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:48.845519Z","iopub.execute_input":"2022-02-17T00:25:48.845755Z","iopub.status.idle":"2022-02-17T00:25:49.980147Z","shell.execute_reply.started":"2022-02-17T00:25:48.845709Z","shell.execute_reply":"2022-02-17T00:25:49.979319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Garment Upper body product group name\ncall(articles,\"Garment Upper body\")","metadata":{"papermill":{"duration":1.159405,"end_time":"2022-02-11T16:46:22.131464","exception":false,"start_time":"2022-02-11T16:46:20.972059","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:49.981224Z","iopub.execute_input":"2022-02-17T00:25:49.981433Z","iopub.status.idle":"2022-02-17T00:25:51.534692Z","shell.execute_reply.started":"2022-02-17T00:25:49.981406Z","shell.execute_reply":"2022-02-17T00:25:51.533883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Accessories product group name\ncall(articles,\"Accessories\")","metadata":{"papermill":{"duration":1.217528,"end_time":"2022-02-11T16:46:23.383936","exception":false,"start_time":"2022-02-11T16:46:22.166408","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:51.535896Z","iopub.execute_input":"2022-02-17T00:25:51.536126Z","iopub.status.idle":"2022-02-17T00:25:53.212283Z","shell.execute_reply.started":"2022-02-17T00:25:51.536095Z","shell.execute_reply":"2022-02-17T00:25:53.211046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Underwear product group name\ncall(articles,\"Underwear\")","metadata":{"papermill":{"duration":1.019619,"end_time":"2022-02-11T16:46:24.443115","exception":false,"start_time":"2022-02-11T16:46:23.423496","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:53.213693Z","iopub.execute_input":"2022-02-17T00:25:53.214414Z","iopub.status.idle":"2022-02-17T00:25:54.311488Z","shell.execute_reply.started":"2022-02-17T00:25:53.214369Z","shell.execute_reply":"2022-02-17T00:25:54.310710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Swimwear product group name\ncall(articles,\"Swimwear\")","metadata":{"papermill":{"duration":1.221084,"end_time":"2022-02-11T16:46:25.709188","exception":false,"start_time":"2022-02-11T16:46:24.488104","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:54.312613Z","iopub.execute_input":"2022-02-17T00:25:54.312856Z","iopub.status.idle":"2022-02-17T00:25:55.402634Z","shell.execute_reply.started":"2022-02-17T00:25:54.312827Z","shell.execute_reply":"2022-02-17T00:25:55.401801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Socks and tights product group name\ncall(articles,\"Socks & Tights\")","metadata":{"papermill":{"duration":1.073909,"end_time":"2022-02-11T16:46:26.832892","exception":false,"start_time":"2022-02-11T16:46:25.758983","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2022-02-17T00:25:55.403660Z","iopub.execute_input":"2022-02-17T00:25:55.403890Z","iopub.status.idle":"2022-02-17T00:25:56.558298Z","shell.execute_reply.started":"2022-02-17T00:25:55.403860Z","shell.execute_reply":"2022-02-17T00:25:56.557402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Ladieswear has the maximum chunk in all unique identifiers  ","metadata":{}},{"cell_type":"code","source":"f, ax = plt.subplots(figsize=(15, 12))\nax = sns.histplot(data=articles, y='garment_group_name', color='orange', hue='index_group_name', multiple=\"stack\")\nax.set_xlabel('count by garment group',size=16)\nax.set_ylabel('garment group',size=16)\nplt.xticks(size=16)\nplt.yticks(size=16)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:56.560013Z","iopub.execute_input":"2022-02-17T00:25:56.560316Z","iopub.status.idle":"2022-02-17T00:25:57.447172Z","shell.execute_reply.started":"2022-02-17T00:25:56.560279Z","shell.execute_reply":"2022-02-17T00:25:57.446634Z"},"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-02-17T00:25:57.448198Z","iopub.execute_input":"2022-02-17T00:25:57.448493Z","iopub.status.idle":"2022-02-17T00:25:57.631639Z","shell.execute_reply.started":"2022-02-17T00:25:57.448466Z","shell.execute_reply":"2022-02-17T00:25:57.630508Z"},"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-02-17T00:25:57.633034Z","iopub.execute_input":"2022-02-17T00:25:57.633344Z","iopub.status.idle":"2022-02-17T00:25:57.821872Z","shell.execute_reply.started":"2022-02-17T00:25:57.633303Z","shell.execute_reply":"2022-02-17T00:25:57.820871Z"},"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'n of unique {col}: {un_n}')","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:57.823328Z","iopub.execute_input":"2022-02-17T00:25:57.823641Z","iopub.status.idle":"2022-02-17T00:25:57.982639Z","shell.execute_reply.started":"2022-02-17T00:25:57.823598Z","shell.execute_reply":"2022-02-17T00:25:57.981868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:57.983724Z","iopub.execute_input":"2022-02-17T00:25:57.983955Z","iopub.status.idle":"2022-02-17T00:25:58.005760Z","shell.execute_reply.started":"2022-02-17T00:25:57.983928Z","shell.execute_reply":"2022-02-17T00:25:58.004867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from wordcloud import WordCloud, STOPWORDS","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:58.006905Z","iopub.execute_input":"2022-02-17T00:25:58.007134Z","iopub.status.idle":"2022-02-17T00:25:58.064618Z","shell.execute_reply.started":"2022-02-17T00:25:58.007106Z","shell.execute_reply":"2022-02-17T00:25:58.063818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stopwords = set(STOPWORDS)\n\ncomment_words = ''\n \n# iterate through the csv file\nfor val in articles.detail_desc:\n     \n    # typecaste each val to string\n    val = str(val)\n \n    # split the value\n    tokens = val.split()\n     \n    # Converts each token into lowercase\n    for i in range(len(tokens)):\n        tokens[i] = tokens[i].lower()\n     \n    comment_words += \" \".join(tokens)+\" \"\nwordcloud = WordCloud(width = 800, height = 800,\n                      background_color ='white',\n                      stopwords = stopwords,\n                      min_font_size = 10).generate(comment_words)\n \n# plot the WordCloud image                      \nplt.figure(figsize = (8, 8), facecolor = None)\nplt.imshow(wordcloud)\nplt.axis(\"off\")\nplt.tight_layout(pad = 0)\n \nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:25:58.065796Z","iopub.execute_input":"2022-02-17T00:25:58.066017Z","iopub.status.idle":"2022-02-17T00:26:07.804020Z","shell.execute_reply.started":"2022-02-17T00:25:58.065988Z","shell.execute_reply":"2022-02-17T00:26:07.803302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Visualization of text data from detail_desc column.\n### The size of each word indicates its frequency or importance","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.club_member_status.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:07.804976Z","iopub.execute_input":"2022-02-17T00:26:07.805181Z","iopub.status.idle":"2022-02-17T00:26:08.010946Z","shell.execute_reply.started":"2022-02-17T00:26:07.805155Z","shell.execute_reply":"2022-02-17T00:26:08.010159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax  = plt.subplots(figsize=(16, 12))\nfig.suptitle('Index Name', size = 20, font=\"Serif\")\nexplode = (0.05, 0.05, 0.05)\nlabels = list(customers.club_member_status.value_counts().index)\nsizes =customers.club_member_status.value_counts().values\nax.pie(sizes,explode=explode,startangle=60, labels=labels,autopct='%1.3f%%', pctdistance=0.7, colors=[\"#4895ef\",\"#f72585\",\"#7209b7\"],textprops={\"fontsize\":15})\nax.add_artist(plt.Circle((0,0),0.4,fc='white'))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:08.012152Z","iopub.execute_input":"2022-02-17T00:26:08.012500Z","iopub.status.idle":"2022-02-17T00:26:08.555294Z","shell.execute_reply.started":"2022-02-17T00:26:08.012469Z","shell.execute_reply":"2022-02-17T00:26:08.554495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:08.556426Z","iopub.execute_input":"2022-02-17T00:26:08.556632Z","iopub.status.idle":"2022-02-17T00:26:08.573307Z","shell.execute_reply.started":"2022-02-17T00:26:08.556606Z","shell.execute_reply":"2022-02-17T00:26:08.572436Z"},"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-02-17T00:26:08.581381Z","iopub.execute_input":"2022-02-17T00:26:08.581894Z","iopub.status.idle":"2022-02-17T00:26:10.541020Z","shell.execute_reply.started":"2022-02-17T00:26:08.581848Z","shell.execute_reply":"2022-02-17T00:26:10.540371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:10.542085Z","iopub.execute_input":"2022-02-17T00:26:10.542407Z","iopub.status.idle":"2022-02-17T00:26:10.552471Z","shell.execute_reply.started":"2022-02-17T00:26:10.542380Z","shell.execute_reply":"2022-02-17T00:26:10.551845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.sales_channel_id.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:10.553648Z","iopub.execute_input":"2022-02-17T00:26:10.554043Z","iopub.status.idle":"2022-02-17T00:26:10.720481Z","shell.execute_reply.started":"2022-02-17T00:26:10.554007Z","shell.execute_reply":"2022-02-17T00:26:10.719625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax  = plt.subplots(figsize=(16, 12))\nfig.suptitle('Sales Channel', size = 20, font=\"Serif\")\nexplode = (0.05, 0.05)\nlabels = list(transactions.sales_channel_id.value_counts().index)\nsizes =transactions.sales_channel_id.value_counts().values\nax.pie(sizes,explode=explode,startangle=60, labels=labels,autopct='%1.3f%%', pctdistance=0.7, colors=[\"#4895ef\",\"#f72585\",\"#7209b7\"],textprops={\"fontsize\":15})\nax.add_artist(plt.Circle((0,0),0.4,fc='white'))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:10.721925Z","iopub.execute_input":"2022-02-17T00:26:10.722200Z","iopub.status.idle":"2022-02-17T00:26:11.199413Z","shell.execute_reply.started":"2022-02-17T00:26:10.722170Z","shell.execute_reply":"2022-02-17T00:26:11.198546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nfrom matplotlib import pyplot as plt\nsns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(10,5))\nax = sns.histplot(data=customers, x='age', bins=50, color='orange')\nax.set_xlabel('Distribution of the customers age')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:11.201345Z","iopub.execute_input":"2022-02-17T00:26:11.202032Z","iopub.status.idle":"2022-02-17T00:26:11.724380Z","shell.execute_reply.started":"2022-02-17T00:26:11.201983Z","shell.execute_reply":"2022-02-17T00:26:11.723474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style(\"darkgrid\")\nf, ax = plt.subplots(figsize=(10,5))\nax = sns.boxplot(data=transactions, x='price', color='orange')\nax.set_xlabel('Price outliers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:11.726018Z","iopub.execute_input":"2022-02-17T00:26:11.726336Z","iopub.status.idle":"2022-02-17T00:26:16.231785Z","shell.execute_reply.started":"2022-02-17T00:26:11.726293Z","shell.execute_reply":"2022-02-17T00:26:16.231081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_byid = transactions.groupby('customer_id').count()\ntransactions_byid.sort_values(by='price', ascending=False)['price'][:10]","metadata":{"execution":{"iopub.status.busy":"2022-02-17T00:26:16.233022Z","iopub.execute_input":"2022-02-17T00:26:16.233227Z","iopub.status.idle":"2022-02-17T00:26:33.230675Z","shell.execute_reply.started":"2022-02-17T00:26:16.233201Z","shell.execute_reply":"2022-02-17T00:26:33.230129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center><h1 style=\"color:red;\">Work in Progress</h1></center>","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}