{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-15T07:04:23.397838Z","iopub.execute_input":"2022-02-15T07:04:23.398114Z","iopub.status.idle":"2022-02-15T07:04:23.40368Z","shell.execute_reply.started":"2022-02-15T07:04:23.398085Z","shell.execute_reply":"2022-02-15T07:04:23.40269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"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.","metadata":{}},{"cell_type":"markdown","source":"Dataset\n\nimages/ - 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\narticles.csv - detailed metadata for each article_id available for purchase\n\ncustomers.csv - metadata for each customer_id in dataset\n\nsample_submission.csv - a sample submission file in the correct format\n\ntransactions_train.csv - the training data, consisting of the purchases each customer for each date, as well as additional information.\n\nDuplicate rows correspond to multiple purchases of the same item. \n\nYour 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":"code","source":"# Install PySpark\n!pip install pyspark > /dev/null","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:04:37.928911Z","iopub.execute_input":"2022-02-15T07:04:37.929181Z","iopub.status.idle":"2022-02-15T07:05:19.059086Z","shell.execute_reply.started":"2022-02-15T07:04:37.92915Z","shell.execute_reply":"2022-02-15T07:05:19.058095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Req libraries\nimport os\nimport numpy as np\nimport pandas as pd\n\nfrom pyspark.sql.types import *\nfrom pyspark.sql.functions import *\nfrom pyspark.sql.window import *","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:05:22.998018Z","iopub.execute_input":"2022-02-15T07:05:22.998784Z","iopub.status.idle":"2022-02-15T07:05:23.158532Z","shell.execute_reply.started":"2022-02-15T07:05:22.998744Z","shell.execute_reply":"2022-02-15T07:05:23.157709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Spark Session\nimport pyspark\nfrom pyspark.sql import SparkSession\n\nspark = SparkSession.builder.appName('fashion-recommendations').getOrCreate()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:05:31.89404Z","iopub.execute_input":"2022-02-15T07:05:31.894299Z","iopub.status.idle":"2022-02-15T07:05:38.345819Z","shell.execute_reply.started":"2022-02-15T07:05:31.894271Z","shell.execute_reply":"2022-02-15T07:05:38.344886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load Data\ntransaction = spark.read.option('header','true').csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:06:40.898302Z","iopub.execute_input":"2022-02-15T07:06:40.899069Z","iopub.status.idle":"2022-02-15T07:06:46.357259Z","shell.execute_reply.started":"2022-02-15T07:06:40.899026Z","shell.execute_reply":"2022-02-15T07:06:46.356401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# filter only 2020\nsales =  transaction.withColumn('t_dat', transaction['t_dat'].cast('string'))\nsales = sales.withColumn('date', from_unixtime(unix_timestamp('t_dat', 'yyyy-MM-dd')))\nsales = sales.withColumn('year', year(col('date')))\nsales = sales.withColumn('month', month(col('date')))\n\n# Let's filter the data to start with\nsales = sales[sales['year'] == 2020]\nsales = sales[sales['month'] == 1]\n\ntransaction.unpersist()\n\n# Prepare the dataset\nsales = sales.groupby('customer_id', 'article_id').count()\nsales.show(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:06:50.98356Z","iopub.execute_input":"2022-02-15T07:06:50.984407Z","iopub.status.idle":"2022-02-15T07:08:50.050142Z","shell.execute_reply.started":"2022-02-15T07:06:50.984353Z","shell.execute_reply":"2022-02-15T07:08:50.049374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Alternative Least Sqaure","metadata":{}},{"cell_type":"code","source":"from pyspark.ml.evaluation import RegressionEvaluator\nfrom pyspark.ml.recommendation import ALS","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:09:26.571879Z","iopub.execute_input":"2022-02-15T07:09:26.572143Z","iopub.status.idle":"2022-02-15T07:09:26.707601Z","shell.execute_reply.started":"2022-02-15T07:09:26.572112Z","shell.execute_reply":"2022-02-15T07:09:26.706903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Converting String to Index","metadata":{}},{"cell_type":"code","source":"from pyspark.ml.feature import StringIndexer\nfrom pyspark.ml import Pipeline\nfrom pyspark.sql.functions import col\n\nindexer = [StringIndexer(inputCol=column, outputCol=column+\"_index\") for column in list(set(sales.columns)-set(['count'])) ]\npipeline = Pipeline(stages=indexer)\ntransformed = pipeline.fit(sales).transform(sales)\ntransformed.show(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:09:46.594909Z","iopub.execute_input":"2022-02-15T07:09:46.595175Z","iopub.status.idle":"2022-02-15T07:15:33.735174Z","shell.execute_reply.started":"2022-02-15T07:09:46.595144Z","shell.execute_reply":"2022-02-15T07:15:33.734497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Creating ALS model and fitting data\n","metadata":{}},{"cell_type":"code","source":"(training,test)=transformed.randomSplit([0.8, 0.2])\n\nals=ALS(maxIter=5,regParam=0.09,rank=25,userCol=\"customer_id_index\",itemCol=\"article_id_index\",ratingCol=\"count\",coldStartStrategy=\"drop\",nonnegative=True)\nmodel=als.fit(training)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:17:58.766212Z","iopub.execute_input":"2022-02-15T07:17:58.766778Z","iopub.status.idle":"2022-02-15T07:26:44.897505Z","shell.execute_reply.started":"2022-02-15T07:17:58.76674Z","shell.execute_reply":"2022-02-15T07:26:44.896682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"evaluator=RegressionEvaluator(metricName=\"rmse\",labelCol=\"count\",predictionCol=\"prediction\")\npredictions=model.transform(test)\nrmse=evaluator.evaluate(predictions)\nprint(\"RMSE=\"+str(rmse))\npredictions.show(5)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:27:46.497741Z","iopub.execute_input":"2022-02-15T07:27:46.498458Z","iopub.status.idle":"2022-02-15T07:32:24.746112Z","shell.execute_reply.started":"2022-02-15T07:27:46.498418Z","shell.execute_reply":"2022-02-15T07:32:24.745466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":{"execution":{"iopub.status.busy":"2022-02-15T07:38:59.059953Z","iopub.execute_input":"2022-02-15T07:38:59.060525Z","iopub.status.idle":"2022-02-15T07:39:00.172594Z","shell.execute_reply.started":"2022-02-15T07:38:59.060485Z","shell.execute_reply":"2022-02-15T07:39:00.171803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMG_DIR=\"../input/h-and-m-personalized-fashion-recommendations/images\"","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:39:07.774944Z","iopub.execute_input":"2022-02-15T07:39:07.775238Z","iopub.status.idle":"2022-02-15T07:39:07.779291Z","shell.execute_reply.started":"2022-02-15T07:39:07.775208Z","shell.execute_reply":"2022-02-15T07:39:07.778459Z"},"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":{"execution":{"iopub.status.busy":"2022-02-15T07:39:13.469715Z","iopub.execute_input":"2022-02-15T07:39:13.469967Z","iopub.status.idle":"2022-02-15T07:39:57.378844Z","shell.execute_reply.started":"2022-02-15T07:39:13.469938Z","shell.execute_reply":"2022-02-15T07:39:57.37803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's display first few rows of all the dataframes","metadata":{}},{"cell_type":"code","source":"articles.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:39:58.939012Z","iopub.execute_input":"2022-02-15T07:39:58.939867Z","iopub.status.idle":"2022-02-15T07:39:58.969895Z","shell.execute_reply.started":"2022-02-15T07:39:58.93982Z","shell.execute_reply":"2022-02-15T07:39:58.969218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:40:05.435388Z","iopub.execute_input":"2022-02-15T07:40:05.43594Z","iopub.status.idle":"2022-02-15T07:40:05.450976Z","shell.execute_reply.started":"2022-02-15T07:40:05.435893Z","shell.execute_reply":"2022-02-15T07:40:05.45036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:40:11.801099Z","iopub.execute_input":"2022-02-15T07:40:11.801412Z","iopub.status.idle":"2022-02-15T07:40:11.814336Z","shell.execute_reply.started":"2022-02-15T07:40:11.801376Z","shell.execute_reply":"2022-02-15T07:40:11.813535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Data Visualization","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":{"execution":{"iopub.status.busy":"2022-02-15T07:40:29.953836Z","iopub.execute_input":"2022-02-15T07:40:29.954122Z","iopub.status.idle":"2022-02-15T07:40:30.020816Z","shell.execute_reply.started":"2022-02-15T07:40:29.954092Z","shell.execute_reply":"2022-02-15T07:40:30.020141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Visualization of missing values","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-15T07:40:51.364196Z","iopub.execute_input":"2022-02-15T07:40:51.364749Z","iopub.status.idle":"2022-02-15T07:40:54.280151Z","shell.execute_reply.started":"2022-02-15T07:40:51.364711Z","shell.execute_reply":"2022-02-15T07:40:54.279508Z"},"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-15T07:41:17.680551Z","iopub.execute_input":"2022-02-15T07:41:17.680808Z","iopub.status.idle":"2022-02-15T07:41:19.718819Z","shell.execute_reply.started":"2022-02-15T07:41:17.68078Z","shell.execute_reply":"2022-02-15T07:41:19.718148Z"},"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-15T07:41:42.42882Z","iopub.execute_input":"2022-02-15T07:41:42.429092Z","iopub.status.idle":"2022-02-15T07:41:56.263957Z","shell.execute_reply.started":"2022-02-15T07:41:42.429064Z","shell.execute_reply":"2022-02-15T07:41:56.26321Z"},"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-15T07:42:03.656118Z","iopub.execute_input":"2022-02-15T07:42:03.656398Z","iopub.status.idle":"2022-02-15T07:42:03.676701Z","shell.execute_reply.started":"2022-02-15T07:42:03.656367Z","shell.execute_reply":"2022-02-15T07:42:03.675887Z"},"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()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:42:11.143247Z","iopub.execute_input":"2022-02-15T07:42:11.143876Z","iopub.status.idle":"2022-02-15T07:42:14.351844Z","shell.execute_reply.started":"2022-02-15T07:42:11.143834Z","shell.execute_reply":"2022-02-15T07:42:14.351166Z"},"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":{"execution":{"iopub.status.busy":"2022-02-15T07:42:39.175103Z","iopub.execute_input":"2022-02-15T07:42:39.175386Z","iopub.status.idle":"2022-02-15T07:42:39.428667Z","shell.execute_reply.started":"2022-02-15T07:42:39.175355Z","shell.execute_reply":"2022-02-15T07:42:39.427818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:42:45.886078Z","iopub.execute_input":"2022-02-15T07:42:45.886359Z","iopub.status.idle":"2022-02-15T07:42:45.90694Z","shell.execute_reply.started":"2022-02-15T07:42:45.886324Z","shell.execute_reply":"2022-02-15T07:42:45.906147Z"},"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-15T07:42:51.584918Z","iopub.execute_input":"2022-02-15T07:42:51.585218Z","iopub.status.idle":"2022-02-15T07:42:52.041739Z","shell.execute_reply.started":"2022-02-15T07:42:51.585188Z","shell.execute_reply":"2022-02-15T07:42:52.040009Z"},"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-15T07:43:13.731696Z","iopub.execute_input":"2022-02-15T07:43:13.732443Z","iopub.status.idle":"2022-02-15T07:43:14.107854Z","shell.execute_reply.started":"2022-02-15T07:43:13.732404Z","shell.execute_reply":"2022-02-15T07:43:14.107179Z"},"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-15T07:43:20.813293Z","iopub.execute_input":"2022-02-15T07:43:20.814056Z","iopub.status.idle":"2022-02-15T07:43:21.23182Z","shell.execute_reply.started":"2022-02-15T07:43:20.814016Z","shell.execute_reply":"2022-02-15T07:43:21.231164Z"},"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-15T07:43:41.491769Z","iopub.execute_input":"2022-02-15T07:43:41.492037Z","iopub.status.idle":"2022-02-15T07:43:42.908904Z","shell.execute_reply.started":"2022-02-15T07:43:41.492006Z","shell.execute_reply":"2022-02-15T07:43:42.908205Z"},"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-15T07:43:58.025724Z","iopub.execute_input":"2022-02-15T07:43:58.025999Z","iopub.status.idle":"2022-02-15T07:43:58.046101Z","shell.execute_reply.started":"2022-02-15T07:43:58.025962Z","shell.execute_reply":"2022-02-15T07:43:58.045356Z"},"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-15T07:44:05.199968Z","iopub.execute_input":"2022-02-15T07:44:05.200238Z","iopub.status.idle":"2022-02-15T07:44:05.361821Z","shell.execute_reply.started":"2022-02-15T07:44:05.200209Z","shell.execute_reply":"2022-02-15T07:44:05.361142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Ladieswear has maximum number of articles followed by Divided and Menswear\n\narticle_id from the articles dataset is same as image id from the image folder Here 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.","metadata":{}},{"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","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:44:40.630598Z","iopub.execute_input":"2022-02-15T07:44:40.630856Z","iopub.status.idle":"2022-02-15T07:44:40.644892Z","shell.execute_reply.started":"2022-02-15T07:44:40.630829Z","shell.execute_reply":"2022-02-15T07:44:40.640639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Garment Lower body product group name\ncall(articles,\"Garment Lower body\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:44:46.756467Z","iopub.execute_input":"2022-02-15T07:44:46.757017Z","iopub.status.idle":"2022-02-15T07:44:48.038953Z","shell.execute_reply.started":"2022-02-15T07:44:46.756974Z","shell.execute_reply":"2022-02-15T07:44:48.038324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Garment Upper body product group name\ncall(articles,\"Garment Upper body\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:44:56.672296Z","iopub.execute_input":"2022-02-15T07:44:56.673104Z","iopub.status.idle":"2022-02-15T07:44:57.840701Z","shell.execute_reply.started":"2022-02-15T07:44:56.67305Z","shell.execute_reply":"2022-02-15T07:44:57.837419Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Accessories product group name\ncall(articles,\"Accessories\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:45:02.948733Z","iopub.execute_input":"2022-02-15T07:45:02.949003Z","iopub.status.idle":"2022-02-15T07:45:04.052288Z","shell.execute_reply.started":"2022-02-15T07:45:02.94897Z","shell.execute_reply":"2022-02-15T07:45:04.051652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Underwear product group name\ncall(articles,\"Underwear\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:45:08.562602Z","iopub.execute_input":"2022-02-15T07:45:08.5633Z","iopub.status.idle":"2022-02-15T07:45:09.522783Z","shell.execute_reply.started":"2022-02-15T07:45:08.563262Z","shell.execute_reply":"2022-02-15T07:45:09.522172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Swimwear product group name\ncall(articles,\"Swimwear\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:45:15.484463Z","iopub.execute_input":"2022-02-15T07:45:15.485173Z","iopub.status.idle":"2022-02-15T07:45:16.457256Z","shell.execute_reply.started":"2022-02-15T07:45:15.485134Z","shell.execute_reply":"2022-02-15T07:45:16.456645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Images from Socks and tights product group name\ncall(articles,\"Socks & Tights\")","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:45:22.229955Z","iopub.execute_input":"2022-02-15T07:45:22.230784Z","iopub.status.idle":"2022-02-15T07:45:23.255944Z","shell.execute_reply.started":"2022-02-15T07:45:22.230731Z","shell.execute_reply":"2022-02-15T07:45:23.25527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Ladieswear has the maximum chunk in all unique identifiers","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:45:38.988371Z","iopub.execute_input":"2022-02-15T07:45:38.989047Z","iopub.status.idle":"2022-02-15T07:45:38.992348Z","shell.execute_reply.started":"2022-02-15T07:45:38.989004Z","shell.execute_reply":"2022-02-15T07:45:38.991554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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-15T07:45:44.006428Z","iopub.execute_input":"2022-02-15T07:45:44.007338Z","iopub.status.idle":"2022-02-15T07:45:44.986904Z","shell.execute_reply.started":"2022-02-15T07:45:44.007273Z","shell.execute_reply":"2022-02-15T07:45:44.986123Z"},"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-15T07:45:51.057031Z","iopub.execute_input":"2022-02-15T07:45:51.057304Z","iopub.status.idle":"2022-02-15T07:45:51.226687Z","shell.execute_reply.started":"2022-02-15T07:45:51.057273Z","shell.execute_reply":"2022-02-15T07:45:51.22601Z"},"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-15T07:45:57.104596Z","iopub.execute_input":"2022-02-15T07:45:57.105196Z","iopub.status.idle":"2022-02-15T07:45:57.295711Z","shell.execute_reply.started":"2022-02-15T07:45:57.105152Z","shell.execute_reply":"2022-02-15T07:45:57.294747Z"},"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-15T07:46:06.331362Z","iopub.execute_input":"2022-02-15T07:46:06.332011Z","iopub.status.idle":"2022-02-15T07:46:06.470078Z","shell.execute_reply.started":"2022-02-15T07:46:06.331962Z","shell.execute_reply":"2022-02-15T07:46:06.469184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:46:12.128844Z","iopub.execute_input":"2022-02-15T07:46:12.129137Z","iopub.status.idle":"2022-02-15T07:46:12.1509Z","shell.execute_reply.started":"2022-02-15T07:46:12.129098Z","shell.execute_reply":"2022-02-15T07:46:12.150089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from wordcloud import WordCloud, STOPWORDS","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:46:19.195901Z","iopub.execute_input":"2022-02-15T07:46:19.19646Z","iopub.status.idle":"2022-02-15T07:46:19.248917Z","shell.execute_reply.started":"2022-02-15T07:46:19.196421Z","shell.execute_reply":"2022-02-15T07:46:19.247942Z"},"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-15T07:46:29.310449Z","iopub.execute_input":"2022-02-15T07:46:29.311174Z","iopub.status.idle":"2022-02-15T07:46:38.141003Z","shell.execute_reply.started":"2022-02-15T07:46:29.311133Z","shell.execute_reply":"2022-02-15T07:46:38.140202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Visualization of text data from detail_desc column.\n\nThe size of each word indicates its frequency or importance","metadata":{}},{"cell_type":"code","source":"customers.club_member_status.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:46:58.119827Z","iopub.execute_input":"2022-02-15T07:46:58.120085Z","iopub.status.idle":"2022-02-15T07:46:58.305161Z","shell.execute_reply.started":"2022-02-15T07:46:58.120057Z","shell.execute_reply":"2022-02-15T07:46:58.304338Z"},"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-15T07:47:03.668733Z","iopub.execute_input":"2022-02-15T07:47:03.669209Z","iopub.status.idle":"2022-02-15T07:47:04.203334Z","shell.execute_reply.started":"2022-02-15T07:47:03.669169Z","shell.execute_reply":"2022-02-15T07:47:04.202655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:47:11.856599Z","iopub.execute_input":"2022-02-15T07:47:11.85726Z","iopub.status.idle":"2022-02-15T07:47:11.868426Z","shell.execute_reply.started":"2022-02-15T07:47:11.857213Z","shell.execute_reply":"2022-02-15T07:47:11.867704Z"},"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-15T07:47:17.992957Z","iopub.execute_input":"2022-02-15T07:47:17.993215Z","iopub.status.idle":"2022-02-15T07:47:19.593927Z","shell.execute_reply.started":"2022-02-15T07:47:17.993186Z","shell.execute_reply":"2022-02-15T07:47:19.5932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:47:23.867825Z","iopub.execute_input":"2022-02-15T07:47:23.868259Z","iopub.status.idle":"2022-02-15T07:47:23.884484Z","shell.execute_reply.started":"2022-02-15T07:47:23.868222Z","shell.execute_reply":"2022-02-15T07:47:23.883764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.sales_channel_id.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-02-15T07:47:29.308739Z","iopub.execute_input":"2022-02-15T07:47:29.309633Z","iopub.status.idle":"2022-02-15T07:47:29.452813Z","shell.execute_reply.started":"2022-02-15T07:47:29.309592Z","shell.execute_reply":"2022-02-15T07:47:29.451978Z"},"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-15T07:47:34.868585Z","iopub.execute_input":"2022-02-15T07:47:34.869361Z","iopub.status.idle":"2022-02-15T07:47:35.284728Z","shell.execute_reply.started":"2022-02-15T07:47:34.869296Z","shell.execute_reply":"2022-02-15T07:47:35.284035Z"},"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-15T07:47:40.864786Z","iopub.execute_input":"2022-02-15T07:47:40.865058Z","iopub.status.idle":"2022-02-15T07:47:41.308637Z","shell.execute_reply.started":"2022-02-15T07:47:40.865026Z","shell.execute_reply":"2022-02-15T07:47:41.307958Z"},"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-15T07:47:46.224205Z","iopub.execute_input":"2022-02-15T07:47:46.224773Z","iopub.status.idle":"2022-02-15T07:47:50.456879Z","shell.execute_reply.started":"2022-02-15T07:47:46.224724Z","shell.execute_reply":"2022-02-15T07:47:50.456182Z"},"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-15T07:47:52.375612Z","iopub.execute_input":"2022-02-15T07:47:52.376494Z","iopub.status.idle":"2022-02-15T07:48:07.375915Z","shell.execute_reply.started":"2022-02-15T07:47:52.376448Z","shell.execute_reply":"2022-02-15T07:48:07.375171Z"},"trusted":true},"execution_count":null,"outputs":[]}]}