{"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":"<h1 align=\"center\" style=\"background-color:yellow;\" style=\"font-family:verdana;\"> ⬆️⬆️⬆️ If you find this note book helpful. <b>please upvote!</b> ⬆️⬆️⬆️ </h1>","metadata":{}},{"cell_type":"markdown","source":"# **H&M Exploratory Data Analysis**","metadata":{"execution":{"iopub.status.busy":"2022-02-09T05:52:20.942547Z","iopub.execute_input":"2022-02-09T05:52:20.942827Z","iopub.status.idle":"2022-02-09T05:52:20.949064Z","shell.execute_reply.started":"2022-02-09T05:52:20.942796Z","shell.execute_reply":"2022-02-09T05:52:20.947795Z"}}},{"cell_type":"markdown","source":"<h1 align=\"center\">\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/5/53/H%26M-Logo.svg\" width=\"200\" height=\"100\" align=\"center\">\n<h1/>","metadata":{"execution":{"iopub.status.busy":"2022-02-09T05:55:17.788897Z","iopub.execute_input":"2022-02-09T05:55:17.789207Z","iopub.status.idle":"2022-02-09T05:55:18.547968Z","shell.execute_reply.started":"2022-02-09T05:55:17.789173Z","shell.execute_reply":"2022-02-09T05:55:18.546732Z"}}},{"cell_type":"markdown","source":"<iframe src=\"https://www.kaggle.com/embed/vanguarde/h-m-eda-first-look?cellIds=1&kernelSessionId=87320319\" height=\"300\" style=\"margin: 0 auto; width: 100%; max-width: 950px;\" frameborder=\"0\" scrolling=\"auto\" title=\"H&amp;M EDA FIRST LOOK\"></iframe>","metadata":{}},{"cell_type":"markdown","source":"# Introduction to the Problem statement...\n* H&M Group is a family of brands and businesses with 53 online markets and approximately 4,850 stores. Our online store offers shoppers an extensive selection of products to browse through. 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, product recommendations are key. More importantly, helping customers make the right choices also has a positive implications for sustainability, as it reduces returns, and thereby minimizes emissions from transportation.\n\n* In this competition, H&M Group invites you to develop product recommendations based on data from previous transactions, as well as from customer and product meta data. The available meta data spans from simple data, such as garment type and customer age, to text data from product descriptions, to image data from garment images.\n\n* There are no preconceptions on what information that may be useful – that is for you to find out. If you want to investigate a categorical data type algorithm, or dive into NLP and image processing deep learning, that is up to you.","metadata":{}},{"cell_type":"markdown","source":"# Data Description\n* For this challenge you are given the purchase history of customers across time, along with supporting metadata. Your challenge is to predict what articles each customer will purchase in the 7-day period immediately after the training data ends. Customer who did not make any purchase during that time are excluded from the scoring.\n\n# Files Includes\n* <b> images</b> - 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.\n* <b>articles.csv</b> - detailed metadata for each article_id available for purchase\n* <b>customers.csv</b> - metadata for each customer_id in dataset\n* <b>sample_submission.csv</b> - a sample submission file in the correct format\n* <b>transactions_train.csv</b> - 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.\n* <b>NOTE:</b> You must make predictions for all customer_id values found in the sample submission. All customers who made purchases during the test period are scored, regardless of whether they had purchase history in the training data.","metadata":{}},{"cell_type":"markdown","source":"# Importing Required Libraries ","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt # for plotting the data \nimport seaborn as sns # Advanced data plotting on top of matplotlib\nimport os\nimport cv2\nimport matplotlib.image as matimg\nfrom pathlib import Path\nimport datatable as dt\nfrom colorama import Fore, Back, Style\nimport plotly.express as px\nfrom PIL import Image\nfrom wordcloud import WordCloud, STOPWORDS, ImageColorGenerator, ImageColorGenerator\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:28.660860Z","iopub.execute_input":"2022-02-21T06:25:28.661366Z","iopub.status.idle":"2022-02-21T06:25:31.525089Z","shell.execute_reply.started":"2022-02-21T06:25:28.661197Z","shell.execute_reply":"2022-02-21T06:25:31.524160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Creating Config class for data locations","metadata":{}},{"cell_type":"code","source":"class Config:\n    image_dir = '../input/h-and-m-personalized-fashion-recommendations/images'\n    article_csv = '../input/h-and-m-personalized-fashion-recommendations/articles.csv'\n    customer_csv = '../input/h-and-m-personalized-fashion-recommendations/customers.csv'\n    tx_csv = '../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv'\n    sub_csv = '../input/h-and-m-personalized-fashion-recommendations/sample_submission.csv'","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:31.527020Z","iopub.execute_input":"2022-02-21T06:25:31.527286Z","iopub.status.idle":"2022-02-21T06:25:31.533100Z","shell.execute_reply.started":"2022-02-21T06:25:31.527254Z","shell.execute_reply":"2022-02-21T06:25:31.531979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Loading the data ","metadata":{}},{"cell_type":"markdown","source":"# Running Analysis on Customer Data","metadata":{}},{"cell_type":"code","source":"%%time\ncustomer_df = pd.read_csv( Config.customer_csv)\ncustomer_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:31.534817Z","iopub.execute_input":"2022-02-21T06:25:31.535102Z","iopub.status.idle":"2022-02-21T06:25:38.593689Z","shell.execute_reply.started":"2022-02-21T06:25:31.535068Z","shell.execute_reply":"2022-02-21T06:25:38.592651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"shape of data Customer data\",customer_df.shape)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:38.595527Z","iopub.execute_input":"2022-02-21T06:25:38.596344Z","iopub.status.idle":"2022-02-21T06:25:38.603400Z","shell.execute_reply.started":"2022-02-21T06:25:38.596305Z","shell.execute_reply":"2022-02-21T06:25:38.602223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Function to plot the Nan percentages of each columns\ndef plot_nas(df: pd.DataFrame):\n    if df.isnull().sum().sum() != 0:\n        na_df = (df.isnull().sum() / len(df)) * 100      \n        na_df = na_df.drop(na_df[na_df == 0].index).sort_values(ascending=False)\n        missing_data = pd.DataFrame({'Missing Ratio %' :na_df})\n        missing_data.plot(kind = \"barh\")\n        plt.show()\n    else:\n        print('No NAs found')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:38.605672Z","iopub.execute_input":"2022-02-21T06:25:38.606914Z","iopub.status.idle":"2022-02-21T06:25:38.615635Z","shell.execute_reply.started":"2022-02-21T06:25:38.606861Z","shell.execute_reply":"2022-02-21T06:25:38.614814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Checking Null's in Customer data \")\nplot_nas(customer_df)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:38.616739Z","iopub.execute_input":"2022-02-21T06:25:38.617054Z","iopub.status.idle":"2022-02-21T06:25:40.164162Z","shell.execute_reply.started":"2022-02-21T06:25:38.617013Z","shell.execute_reply":"2022-02-21T06:25:40.163280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def print_unique(customer_df, only_nunique = True):\n    print( 'No. of unique values' )\n    for col in customer_df.columns:\n        print( Back.CYAN+ f'No of unique {col} -> {customer_df[col].nunique()} ')\n    print(Fore.RESET)\n    if not only_nunique:\n        print('Unique values' )\n        for col in customer_df.columns:\n            print( f'Unique values in {col} -> {customer_df[col].unique()} ')\nprint_unique(customer_df, False)\n","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:40.165476Z","iopub.execute_input":"2022-02-21T06:25:40.165751Z","iopub.status.idle":"2022-02-21T06:25:43.634168Z","shell.execute_reply.started":"2022-02-21T06:25:40.165720Z","shell.execute_reply":"2022-02-21T06:25:43.633154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_bar(df, column):\n    long_df = pd.DataFrame(df.groupby(column)['customer_id'].count().reset_index().rename({'customer_id': 'count'}, axis=1))\n    fig = px.bar(long_df, x=column, y=\"count\", color=column, title=f\"bar plot for {column} \")\n    fig.show()\n    \ndef plot_hist(df, column):\n    fig = px.histogram(df, x=column, nbins=10, title=f'{column} distribution ')\n    fig.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:43.635842Z","iopub.execute_input":"2022-02-21T06:25:43.636109Z","iopub.status.idle":"2022-02-21T06:25:43.643980Z","shell.execute_reply.started":"2022-02-21T06:25:43.636077Z","shell.execute_reply":"2022-02-21T06:25:43.642892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar( customer_df, 'club_member_status')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:43.645637Z","iopub.execute_input":"2022-02-21T06:25:43.646661Z","iopub.status.idle":"2022-02-21T06:25:45.077181Z","shell.execute_reply.started":"2022-02-21T06:25:43.646624Z","shell.execute_reply":"2022-02-21T06:25:45.075878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_hist( customer_df, 'age')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:45.080481Z","iopub.execute_input":"2022-02-21T06:25:45.081090Z","iopub.status.idle":"2022-02-21T06:25:52.290347Z","shell.execute_reply.started":"2022-02-21T06:25:45.081049Z","shell.execute_reply":"2022-02-21T06:25:52.286641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar( customer_df, 'fashion_news_frequency')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:52.292485Z","iopub.execute_input":"2022-02-21T06:25:52.293184Z","iopub.status.idle":"2022-02-21T06:25:52.737070Z","shell.execute_reply.started":"2022-02-21T06:25:52.293125Z","shell.execute_reply":"2022-02-21T06:25:52.735819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Running Analysis on Article Data","metadata":{"execution":{"iopub.status.busy":"2022-02-09T06:18:25.026027Z","iopub.execute_input":"2022-02-09T06:18:25.02634Z","iopub.status.idle":"2022-02-09T06:18:25.032101Z","shell.execute_reply.started":"2022-02-09T06:18:25.026311Z","shell.execute_reply":"2022-02-09T06:18:25.031294Z"}}},{"cell_type":"code","source":"%%time\narticle_df = pd.read_csv( Config.article_csv)\narticle_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:52.738616Z","iopub.execute_input":"2022-02-21T06:25:52.739218Z","iopub.status.idle":"2022-02-21T06:25:53.937350Z","shell.execute_reply.started":"2022-02-21T06:25:52.739176Z","shell.execute_reply":"2022-02-21T06:25:53.936539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"shape of data Article data\",article_df.shape)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-21T06:25:53.938768Z","iopub.execute_input":"2022-02-21T06:25:53.939011Z","iopub.status.idle":"2022-02-21T06:25:53.944816Z","shell.execute_reply.started":"2022-02-21T06:25:53.938982Z","shell.execute_reply":"2022-02-21T06:25:53.943641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Checking Null's in Article data \")\nplot_nas(article_df)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:53.946369Z","iopub.execute_input":"2022-02-21T06:25:53.946639Z","iopub.status.idle":"2022-02-21T06:25:54.454813Z","shell.execute_reply.started":"2022-02-21T06:25:53.946605Z","shell.execute_reply":"2022-02-21T06:25:54.453801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print_unique(article_df, False)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:54.456770Z","iopub.execute_input":"2022-02-21T06:25:54.457112Z","iopub.status.idle":"2022-02-21T06:25:54.808900Z","shell.execute_reply.started":"2022-02-21T06:25:54.457063Z","shell.execute_reply":"2022-02-21T06:25:54.807854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_bar(df, column):\n    long_df = pd.DataFrame(df.groupby(column)['article_id'].count().reset_index().rename({'article_id': 'count'}, axis=1))\n    fig = px.bar(long_df, x=column, y=\"count\", color=column, title=f\"bar plot for {column} \")\n    fig.show()\n    \ndef plot_hist(df, column):\n    fig = px.histogram(df, x=column, nbins=10, title=f'{column} distribution ')\n    fig.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:54.810481Z","iopub.execute_input":"2022-02-21T06:25:54.810738Z","iopub.status.idle":"2022-02-21T06:25:54.818428Z","shell.execute_reply.started":"2022-02-21T06:25:54.810709Z","shell.execute_reply":"2022-02-21T06:25:54.817165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar(article_df,'product_type_name')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:54.819926Z","iopub.execute_input":"2022-02-21T06:25:54.820233Z","iopub.status.idle":"2022-02-21T06:25:55.493672Z","shell.execute_reply.started":"2022-02-21T06:25:54.820156Z","shell.execute_reply":"2022-02-21T06:25:55.492848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar(article_df,'product_group_name')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:55.494966Z","iopub.execute_input":"2022-02-21T06:25:55.495205Z","iopub.status.idle":"2022-02-21T06:25:55.662072Z","shell.execute_reply.started":"2022-02-21T06:25:55.495175Z","shell.execute_reply":"2022-02-21T06:25:55.661270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar(article_df,'graphical_appearance_name')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:55.663300Z","iopub.execute_input":"2022-02-21T06:25:55.663569Z","iopub.status.idle":"2022-02-21T06:25:55.871485Z","shell.execute_reply.started":"2022-02-21T06:25:55.663536Z","shell.execute_reply":"2022-02-21T06:25:55.870571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar(article_df,'index_name')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:55.872811Z","iopub.execute_input":"2022-02-21T06:25:55.873063Z","iopub.status.idle":"2022-02-21T06:25:55.989664Z","shell.execute_reply.started":"2022-02-21T06:25:55.873033Z","shell.execute_reply":"2022-02-21T06:25:55.988988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# article_df.groupby('garment_group_name')['article_id'].count()\nplot_bar(article_df,'garment_group_name')","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:55.990654Z","iopub.execute_input":"2022-02-21T06:25:55.991388Z","iopub.status.idle":"2022-02-21T06:25:56.158417Z","shell.execute_reply.started":"2022-02-21T06:25:55.991349Z","shell.execute_reply":"2022-02-21T06:25:56.157347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#  Transaction Data Analysis","metadata":{"execution":{"iopub.status.busy":"2022-02-09T07:01:18.360275Z","iopub.execute_input":"2022-02-09T07:01:18.360547Z","iopub.status.idle":"2022-02-09T07:01:18.364829Z","shell.execute_reply.started":"2022-02-09T07:01:18.360516Z","shell.execute_reply":"2022-02-09T07:01:18.363809Z"}}},{"cell_type":"code","source":"tran_df = pd.read_csv( Config.tx_csv)\ntran_df['t_dat']=pd.to_datetime(tran_df['t_dat'])\ntran_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:25:56.159823Z","iopub.execute_input":"2022-02-21T06:25:56.160173Z","iopub.status.idle":"2022-02-21T06:27:12.789367Z","shell.execute_reply.started":"2022-02-21T06:25:56.160137Z","shell.execute_reply":"2022-02-21T06:27:12.788520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"shape of data Transaction data\",tran_df.shape)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:27:12.791063Z","iopub.execute_input":"2022-02-21T06:27:12.791592Z","iopub.status.idle":"2022-02-21T06:27:12.797077Z","shell.execute_reply.started":"2022-02-21T06:27:12.791513Z","shell.execute_reply":"2022-02-21T06:27:12.796230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Checking Null's in Transaction data \")\nplot_nas(tran_df)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:27:12.798585Z","iopub.execute_input":"2022-02-21T06:27:12.799090Z","iopub.status.idle":"2022-02-21T06:27:16.447051Z","shell.execute_reply.started":"2022-02-21T06:27:12.799042Z","shell.execute_reply":"2022-02-21T06:27:16.446135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print_unique(tran_df, False)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:27:16.448675Z","iopub.execute_input":"2022-02-21T06:27:16.449177Z","iopub.status.idle":"2022-02-21T06:27:35.935444Z","shell.execute_reply.started":"2022-02-21T06:27:16.449125Z","shell.execute_reply":"2022-02-21T06:27:35.934493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar( tran_df, 'sales_channel_id' )","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:27:35.937077Z","iopub.execute_input":"2022-02-21T06:27:35.937957Z","iopub.status.idle":"2022-02-21T06:27:36.621943Z","shell.execute_reply.started":"2022-02-21T06:27:35.937900Z","shell.execute_reply":"2022-02-21T06:27:36.621257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = tran_df.groupby('t_dat')['price'].agg(['sum', 'mean']).sort_values(by = 't_dat', ascending=False).reset_index()\nfig = px.bar( df, x='t_dat', y='sum', title='Total Sales daily')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:27:36.623027Z","iopub.execute_input":"2022-02-21T06:27:36.623969Z","iopub.status.idle":"2022-02-21T06:27:37.682823Z","shell.execute_reply.started":"2022-02-21T06:27:36.623929Z","shell.execute_reply":"2022-02-21T06:27:37.681645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##  week day sales\ndays = [\"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"]\ndays_dict = dict(zip(range(7), days))\ndf=pd.DataFrame()\ndf['weekday'] = tran_df['t_dat'].dt.weekday.map( days_dict)\ndf['price'] = tran_df.price\ndf = df.groupby('weekday')['price'].agg(['sum']).sort_values(by = 'sum', ascending=False).reset_index()\nfig = px.bar( df, x='weekday', y='sum', title='Weeky sales ', color='weekday')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:27:37.687495Z","iopub.execute_input":"2022-02-21T06:27:37.687826Z","iopub.status.idle":"2022-02-21T06:27:49.878666Z","shell.execute_reply.started":"2022-02-21T06:27:37.687794Z","shell.execute_reply":"2022-02-21T06:27:49.877522Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"months = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\ndays_dict = dict(zip(range(13), months))\ndf=pd.DataFrame()\ndf['month'] = tran_df['t_dat'].dt.month.map( days_dict)\ndf['price'] = tran_df.price\ndf = df.groupby('month')['price'].agg(['sum']).sort_values(by = 'sum', ascending=False).reset_index()\nfig = px.bar( df, x='month', y='sum', title='Monthly sales ', color=\"month\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:27:49.880365Z","iopub.execute_input":"2022-02-21T06:27:49.880718Z","iopub.status.idle":"2022-02-21T06:28:01.813868Z","shell.execute_reply.started":"2022-02-21T06:27:49.880675Z","shell.execute_reply":"2022-02-21T06:28:01.813179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Images With Description ","metadata":{"execution":{"iopub.status.busy":"2022-02-09T09:09:11.225811Z","iopub.execute_input":"2022-02-09T09:09:11.226383Z","iopub.status.idle":"2022-02-09T09:09:11.31451Z","shell.execute_reply.started":"2022-02-09T09:09:11.226284Z","shell.execute_reply":"2022-02-09T09:09:11.313451Z"}}},{"cell_type":"code","source":"def display_image_with_desc(n_image=10):\n    images = list(Path('../input/h-and-m-personalized-fashion-recommendations/images/011').glob('*.jpg'))\n    fig, ax = plt.subplots(1,n_image,  figsize=(20,30))\n    \n    for i, image in enumerate(images[:n_image]):\n        img = matimg.imread(image)\n        articel_id = str(image).split('/')[-1].split('.')[0][1:]\n        article_desc = article_df[article_df['article_id']== int(articel_id)].loc[:,'detail_desc'].values[0]\n        desc_list = article_desc.split(' ')\n        for j, elem in enumerate(desc_list):\n            if j > 0 and j % 5 == 0:\n                desc_list[j] = desc_list[j] + '\\n'\n        desc = ' '.join(desc_list)\n        ax[i].set_xticks([], [])\n        ax[i].set_yticks([], [])\n        ax[i].grid(False)\n        ax[i].set_xlabel(desc, fontsize=10)\n        ax[i].imshow(img)\n    plt.tight_layout(pad=0)\n    plt.show()\ndisplay_image_with_desc(10)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:01.814853Z","iopub.execute_input":"2022-02-21T06:28:01.815211Z","iopub.status.idle":"2022-02-21T06:28:05.156328Z","shell.execute_reply.started":"2022-02-21T06:28:01.815181Z","shell.execute_reply":"2022-02-21T06:28:05.155613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"product_list = article_df['product_type_name'].unique()\nlen(product_list)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:05.157371Z","iopub.execute_input":"2022-02-21T06:28:05.158293Z","iopub.status.idle":"2022-02-21T06:28:05.180229Z","shell.execute_reply.started":"2022-02-21T06:28:05.158220Z","shell.execute_reply":"2022-02-21T06:28:05.179343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_sample_image(product_type_name=\"Vest top\"):\n    \"\"\"\n        dir_num is \"010\", \"011\", \"012\",...\" 095\".\n    If dir_num is specified, up to four images of each dir will be displayed randomly.\n    \"\"\"\n    base_path = '../input/h-and-m-personalized-fashion-recommendations/images'\n    \n    articles_data_new = article_df[article_df[\"product_type_name\"]==product_type_name]\n    articles_data_new.reset_index(drop=True)\n    \n    fig = plt.figure(figsize=(16,4))\n    plt.title(\"product_type_name: {}\".format(product_type_name))\n    plt.yticks([])\n    plt.xticks([])\n\n    k = min(len(article_df), 5)\n    for i in range(k):\n        index = np.random.randint(len(articles_data_new))\n        article_id = \"0\" + str(articles_data_new.iloc[index][\"article_id\"]) + \".jpg\"\n        \n        img_path = os.path.join(base_path, article_id[0:3])\n        img_path = os.path.join(img_path, article_id)\n\n        sample_pic = cv2.imread(img_path)\n        \n        ax = fig.add_subplot(1,5,i+1)\n        ax.imshow(sample_pic)\n    \n    plt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:05.182046Z","iopub.execute_input":"2022-02-21T06:28:05.183116Z","iopub.status.idle":"2022-02-21T06:28:05.194458Z","shell.execute_reply.started":"2022-02-21T06:28:05.183063Z","shell.execute_reply":"2022-02-21T06:28:05.193495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=\"Vest top\")","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:05.195560Z","iopub.execute_input":"2022-02-21T06:28:05.196101Z","iopub.status.idle":"2022-02-21T06:28:07.763758Z","shell.execute_reply.started":"2022-02-21T06:28:05.196063Z","shell.execute_reply":"2022-02-21T06:28:07.762823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[1])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:07.765329Z","iopub.execute_input":"2022-02-21T06:28:07.765594Z","iopub.status.idle":"2022-02-21T06:28:10.282655Z","shell.execute_reply.started":"2022-02-21T06:28:07.765561Z","shell.execute_reply":"2022-02-21T06:28:10.281756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[2])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:10.283980Z","iopub.execute_input":"2022-02-21T06:28:10.284230Z","iopub.status.idle":"2022-02-21T06:28:12.756924Z","shell.execute_reply.started":"2022-02-21T06:28:10.284198Z","shell.execute_reply":"2022-02-21T06:28:12.755803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[3])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:12.758245Z","iopub.execute_input":"2022-02-21T06:28:12.758464Z","iopub.status.idle":"2022-02-21T06:28:15.276795Z","shell.execute_reply.started":"2022-02-21T06:28:12.758436Z","shell.execute_reply":"2022-02-21T06:28:15.275995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[4])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:15.278115Z","iopub.execute_input":"2022-02-21T06:28:15.278492Z","iopub.status.idle":"2022-02-21T06:28:17.902796Z","shell.execute_reply.started":"2022-02-21T06:28:15.278461Z","shell.execute_reply":"2022-02-21T06:28:17.902146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[5])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:17.903919Z","iopub.execute_input":"2022-02-21T06:28:17.904489Z","iopub.status.idle":"2022-02-21T06:28:20.458308Z","shell.execute_reply.started":"2022-02-21T06:28:17.904455Z","shell.execute_reply":"2022-02-21T06:28:20.457605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[6])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:20.459589Z","iopub.execute_input":"2022-02-21T06:28:20.459968Z","iopub.status.idle":"2022-02-21T06:28:23.191253Z","shell.execute_reply.started":"2022-02-21T06:28:20.459925Z","shell.execute_reply":"2022-02-21T06:28:23.190541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[7])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:23.192492Z","iopub.execute_input":"2022-02-21T06:28:23.196897Z","iopub.status.idle":"2022-02-21T06:28:25.719245Z","shell.execute_reply.started":"2022-02-21T06:28:23.196830Z","shell.execute_reply":"2022-02-21T06:28:25.718162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[8])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:25.720716Z","iopub.execute_input":"2022-02-21T06:28:25.721101Z","iopub.status.idle":"2022-02-21T06:28:28.212406Z","shell.execute_reply.started":"2022-02-21T06:28:25.721067Z","shell.execute_reply":"2022-02-21T06:28:28.211486Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[9])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:28.214216Z","iopub.execute_input":"2022-02-21T06:28:28.214796Z","iopub.status.idle":"2022-02-21T06:28:30.920990Z","shell.execute_reply.started":"2022-02-21T06:28:28.214735Z","shell.execute_reply":"2022-02-21T06:28:30.919856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_sample_image(product_type_name=product_list[10])","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:30.922583Z","iopub.execute_input":"2022-02-21T06:28:30.922860Z","iopub.status.idle":"2022-02-21T06:28:33.419096Z","shell.execute_reply.started":"2022-02-21T06:28:30.922823Z","shell.execute_reply":"2022-02-21T06:28:33.418210Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_image_with_desc(n_image=10):\n    images = list(Path('../input/h-and-m-personalized-fashion-recommendations/images/011').glob('*.jpg'))\n    fig, ax = plt.subplots(1,n_image,  figsize=(20,30))\n    \n    for i, image in enumerate(images[:n_image]):\n        img = matimg.imread(image)\n        articel_id = str(image).split('/')[-1].split('.')[0][1:]\n        article_desc = article_df[article_df['article_id']== int(articel_id)].loc[:,'detail_desc'].values[0]\n        desc_list = article_desc.split(' ')\n        for j, elem in enumerate(desc_list):\n            if j > 0 and j % 5 == 0:\n                desc_list[j] = desc_list[j] + '\\n'\n        desc = ' '.join(desc_list)\n        ax[i].set_xticks([], [])\n        ax[i].set_yticks([], [])\n        ax[i].grid(False)\n        ax[i].set_xlabel(desc, fontsize=10)\n        ax[i].imshow(img)\n    plt.tight_layout(pad=0)\n    plt.show()\ndisplay_image_with_desc(10)","metadata":{"execution":{"iopub.status.busy":"2022-02-21T06:28:33.420482Z","iopub.execute_input":"2022-02-21T06:28:33.420758Z","iopub.status.idle":"2022-02-21T06:28:36.472366Z","shell.execute_reply.started":"2022-02-21T06:28:33.420726Z","shell.execute_reply":"2022-02-21T06:28:36.471199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"alert alert-block alert-info\">\n<h1 align='center'> <b>Work in Progress!</b> </h1>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<h1 align=\"center\" style=\"background-color:yellow;\" style=\"font-family:verdana;\"> ⬆️⬆️⬆️ If you find this note book helpful. <b>please upvote!</b> ⬆️⬆️⬆️ </h1>","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}