{"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":"# Acknowledgement\n- This notebook is copied from the original notebook by GABRIEL PREDA: [Link](https://www.kaggle.com/gpreda/h-m-eda-and-prediction). All credit to the original author!\n- I've just updated the plots to Plotly as they allow for full interactivity with lesser lines of code!","metadata":{}},{"cell_type":"markdown","source":"# Introduction\n\nThe dataset contains 4 csv files and one folder with several subfolders, each with a different number of images.\n\nIn this Exploratory Data Analysis Notebook we will look to the data, will analyze the content of each csv file, check for missing data, understand the data distribution, see what are the relations between data in various files.\n\nWe will also explore the image data, understand how images are indexed in the csv files, if there are articles in the dataset without images. We will also explore image additional information, like image width and height.\n\nWe also investigate a very simple baseline model and create an initial submission.\n\n\n\n<img src=\"https://images.unsplash.com/photo-1578983662508-41895226ebfb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1211&q=80\" width=600></img>\n","metadata":{}},{"cell_type":"markdown","source":"# Analysis preparation\n\nWe will include here the required packages for reading, parsing, filtering, processing, visualizing the data, both tabular and image.\n\n<img src=\"https://images.unsplash.com/photo-1607160199580-1b0c9b736b66?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2070&q=80\" width=600></img>\n","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nfrom tqdm import tqdm\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom wordcloud import WordCloud, STOPWORDS\nfrom datetime import datetime\nfrom PIL import Image\n\n# Plotly code\nimport plotly.express as px\nimport plotly.figure_factory as ff","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:12:42.705046Z","iopub.execute_input":"2022-02-13T07:12:42.705388Z","iopub.status.idle":"2022-02-13T07:12:43.740724Z","shell.execute_reply.started":"2022-02-13T07:12:42.705353Z","shell.execute_reply":"2022-02-13T07:12:43.739958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Read and glimpse the data\n\n<img src=\"https://images.unsplash.com/photo-1532453288672-3a27e9be9efd?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80\" width=400></img>","metadata":{}},{"cell_type":"code","source":"print(f\"files and folders: {os.listdir('/kaggle/input/h-and-m-personalized-fashion-recommendations/')}\")\nprint(\"Subfolders in images folder: \", len(list(os.listdir(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/images\"))))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:42:33.681273Z","iopub.execute_input":"2022-02-13T06:42:33.6816Z","iopub.status.idle":"2022-02-13T06:42:33.694908Z","shell.execute_reply.started":"2022-02-13T06:42:33.681555Z","shell.execute_reply":"2022-02-13T06:42:33.693376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_folders = total_files = 0\nfolder_info = []\nimages_names = []\nfor base, dirs, files in tqdm(os.walk('/kaggle/input/h-and-m-personalized-fashion-recommendations/')):\n    for directories in dirs:\n        folder_info.append((directories, len(os.listdir(os.path.join(base, directories)))))\n        total_folders += 1\n    for _files in files:\n        total_files += 1\n        if len(_files.split(\".jpg\"))==2:\n            images_names.append(_files.split(\".jpg\")[0])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:42:33.696334Z","iopub.execute_input":"2022-02-13T06:42:33.696754Z","iopub.status.idle":"2022-02-13T06:43:28.648093Z","shell.execute_reply.started":"2022-02-13T06:42:33.696719Z","shell.execute_reply":"2022-02-13T06:43:28.647122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"Total number of folders: {total_folders}\\nTotal number of files: {total_files}\")\nfolder_info_df = pd.DataFrame(folder_info, columns=[\"folder\", \"files count\"])\nfolder_info_df.sort_values([\"files count\"], ascending=False).head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:43:28.650465Z","iopub.execute_input":"2022-02-13T06:43:28.650728Z","iopub.status.idle":"2022-02-13T06:43:28.687439Z","shell.execute_reply.started":"2022-02-13T06:43:28.650687Z","shell.execute_reply":"2022-02-13T06:43:28.686361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"folder names: \", list(folder_info_df.folder.unique()))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:43:28.689392Z","iopub.execute_input":"2022-02-13T06:43:28.69028Z","iopub.status.idle":"2022-02-13T06:43:28.700519Z","shell.execute_reply.started":"2022-02-13T06:43:28.690232Z","shell.execute_reply":"2022-02-13T06:43:28.699524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_df = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ncustomers_df = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv\")\nsample_submission_df = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/sample_submission.csv\")\ntransactions_train_df = pd.read_csv(\"/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:43:28.701815Z","iopub.execute_input":"2022-02-13T06:43:28.702166Z","iopub.status.idle":"2022-02-13T06:44:44.819706Z","shell.execute_reply.started":"2022-02-13T06:43:28.702136Z","shell.execute_reply":"2022-02-13T06:44:44.818743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:44.821348Z","iopub.execute_input":"2022-02-13T06:44:44.821704Z","iopub.status.idle":"2022-02-13T06:44:44.858933Z","shell.execute_reply.started":"2022-02-13T06:44:44.82164Z","shell.execute_reply":"2022-02-13T06:44:44.857961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:44.873128Z","iopub.execute_input":"2022-02-13T06:44:44.873559Z","iopub.status.idle":"2022-02-13T06:44:44.890425Z","shell.execute_reply.started":"2022-02-13T06:44:44.873511Z","shell.execute_reply":"2022-02-13T06:44:44.889699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:44.891651Z","iopub.execute_input":"2022-02-13T06:44:44.892052Z","iopub.status.idle":"2022-02-13T06:44:44.911148Z","shell.execute_reply.started":"2022-02-13T06:44:44.892007Z","shell.execute_reply":"2022-02-13T06:44:44.909761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:44.914621Z","iopub.execute_input":"2022-02-13T06:44:44.915394Z","iopub.status.idle":"2022-02-13T06:44:44.928548Z","shell.execute_reply.started":"2022-02-13T06:44:44.915357Z","shell.execute_reply":"2022-02-13T06:44:44.927263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_df.info()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:44.929782Z","iopub.execute_input":"2022-02-13T06:44:44.930022Z","iopub.status.idle":"2022-02-13T06:44:45.088154Z","shell.execute_reply.started":"2022-02-13T06:44:44.929981Z","shell.execute_reply":"2022-02-13T06:44:45.086909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers_df.info()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:45.09179Z","iopub.execute_input":"2022-02-13T06:44:45.092054Z","iopub.status.idle":"2022-02-13T06:44:45.623779Z","shell.execute_reply.started":"2022-02-13T06:44:45.092022Z","shell.execute_reply":"2022-02-13T06:44:45.622861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission_df.info()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:45.624967Z","iopub.execute_input":"2022-02-13T06:44:45.625298Z","iopub.status.idle":"2022-02-13T06:44:45.882628Z","shell.execute_reply.started":"2022-02-13T06:44:45.625264Z","shell.execute_reply":"2022-02-13T06:44:45.881707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train_df.info()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:45.88411Z","iopub.execute_input":"2022-02-13T06:44:45.88439Z","iopub.status.idle":"2022-02-13T06:44:45.896703Z","shell.execute_reply.started":"2022-02-13T06:44:45.884355Z","shell.execute_reply":"2022-02-13T06:44:45.895696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Let's look closer to the data\n\n<img src=\"https://images.unsplash.com/photo-1569484221992-2a453658fff3?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1179&q=80\" width=600></img>\n\nThere are 3 main tables:\n- articles - contains informations about each article (like product code, name, product group code, name ...)    \n- customers - contains informations about each customer (fidelity card membership, age, postal code)\n- transactions (train)  \n\nTransactions have `customer_id` and `article_id`, which are foreign keys for the customer and articles tables.\nBeside this, transaction also contains `sales_channel_id`.\n\n\n","metadata":{}},{"cell_type":"markdown","source":"# Articles data","metadata":{}},{"cell_type":"code","source":"temp = articles_df.groupby([\"product_group_name\"])[\"product_type_name\"].nunique()\ndf = pd.DataFrame({'Product Group': temp.index,\n                   'Product Types': temp.values\n                  })\ndf = df.sort_values(['Product Types'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Product Group', y='Product Types', \n       title='Number of Product Types per each Product Group', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T06:44:45.898212Z","iopub.execute_input":"2022-02-13T06:44:45.898949Z","iopub.status.idle":"2022-02-13T06:44:47.28482Z","shell.execute_reply.started":"2022-02-13T06:44:45.898904Z","shell.execute_reply":"2022-02-13T06:44:47.283758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stopwords = set(STOPWORDS)\n\ndef show_wordcloud(data, title = None):\n    wordcloud = WordCloud(\n        background_color='white',\n        stopwords=stopwords,\n        max_words=200,\n        max_font_size=40, \n        scale=5,\n        random_state=1\n    ).generate(str(data))\n\n    fig = plt.figure(1, figsize=(10,10))\n    plt.axis('off')\n    if title: \n        fig.suptitle(title, fontsize=14)\n        fig.subplots_adjust(top=2.3)\n\n    plt.imshow(wordcloud)\n    plt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:47.286114Z","iopub.execute_input":"2022-02-13T06:44:47.28634Z","iopub.status.idle":"2022-02-13T06:44:47.294617Z","shell.execute_reply.started":"2022-02-13T06:44:47.286309Z","shell.execute_reply":"2022-02-13T06:44:47.293228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_wordcloud(articles_df[\"prod_name\"], \"Wordcloud from product name\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T06:44:47.295922Z","iopub.execute_input":"2022-02-13T06:44:47.296223Z","iopub.status.idle":"2022-02-13T06:44:48.020536Z","shell.execute_reply.started":"2022-02-13T06:44:47.296167Z","shell.execute_reply":"2022-02-13T06:44:48.019791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"product_group_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Product Group': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Product Group', y='Articles', \n       title='Number of Articles per each Product Group', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T06:44:48.021862Z","iopub.execute_input":"2022-02-13T06:44:48.022262Z","iopub.status.idle":"2022-02-13T06:44:48.132914Z","shell.execute_reply.started":"2022-02-13T06:44:48.02223Z","shell.execute_reply":"2022-02-13T06:44:48.132101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"product_type_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Product Type': temp.index,\n                   'Articles': temp.values\n                  })\ntotal_types = len(df['Product Type'].unique())\ndf = df.sort_values(['Articles'], ascending=False)[0:50]\n\n# Plotly code\npx.bar(df, x='Product Type', y='Articles', \n       title=f'Number of Articles per each Product Type (top 50 from total: {total_types})', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T06:44:48.134174Z","iopub.execute_input":"2022-02-13T06:44:48.134712Z","iopub.status.idle":"2022-02-13T06:44:48.244115Z","shell.execute_reply.started":"2022-02-13T06:44:48.134605Z","shell.execute_reply":"2022-02-13T06:44:48.242889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"department_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Department Name': temp.index,\n                   'Articles': temp.values\n                  })\ntotal_depts = len(df['Department Name'].unique())\ndf = df.sort_values(['Articles'], ascending=False).head(50)\n\n# Plotly code\npx.bar(df, x='Department Name', y='Articles', \n       title=f'Number of Articles per each Department (top 50 from total: {total_depts})', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T05:15:08.236683Z","iopub.execute_input":"2022-02-13T05:15:08.236927Z","iopub.status.idle":"2022-02-13T05:15:08.348065Z","shell.execute_reply.started":"2022-02-13T05:15:08.236897Z","shell.execute_reply":"2022-02-13T05:15:08.347091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"graphical_appearance_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Graphical Appearance Name': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False).head(50)\n\n# Plotly code\npx.bar(df, x='Graphical Appearance Name', y='Articles', \n       title='Number of Articles per each Graphical Appearance Name', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:00:11.719786Z","iopub.execute_input":"2022-02-13T07:00:11.721199Z","iopub.status.idle":"2022-02-13T07:00:11.869675Z","shell.execute_reply.started":"2022-02-13T07:00:11.721123Z","shell.execute_reply":"2022-02-13T07:00:11.868748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"index_group_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Index Group Name': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Index Group Name', y='Articles', \n       title='Number of Articles per each Index Group Name', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:01:15.538334Z","iopub.execute_input":"2022-02-13T07:01:15.538857Z","iopub.status.idle":"2022-02-13T07:01:15.6377Z","shell.execute_reply.started":"2022-02-13T07:01:15.538824Z","shell.execute_reply":"2022-02-13T07:01:15.636807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"colour_group_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Colour Group Name': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Colour Group Name', y='Articles', \n       title='Number of Articles per each Colour Group Name', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:01:57.58235Z","iopub.execute_input":"2022-02-13T07:01:57.582692Z","iopub.status.idle":"2022-02-13T07:01:57.694746Z","shell.execute_reply.started":"2022-02-13T07:01:57.582637Z","shell.execute_reply":"2022-02-13T07:01:57.693812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"perceived_colour_value_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Perceived Colour Group Name': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Perceived Colour Group Name', y='Articles', \n       title='Number of Articles per each Perceived Colour Group Name', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:02:46.97794Z","iopub.execute_input":"2022-02-13T07:02:46.978227Z","iopub.status.idle":"2022-02-13T07:02:47.082868Z","shell.execute_reply.started":"2022-02-13T07:02:46.978196Z","shell.execute_reply":"2022-02-13T07:02:47.081694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"perceived_colour_master_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Perceived Colour Master Name': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Perceived Colour Master Name', y='Articles', \n       title='Number of Articles per each Perceived Colour Master Name', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:03:51.312252Z","iopub.execute_input":"2022-02-13T07:03:51.312571Z","iopub.status.idle":"2022-02-13T07:03:51.417617Z","shell.execute_reply.started":"2022-02-13T07:03:51.312534Z","shell.execute_reply":"2022-02-13T07:03:51.416905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"index_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Index Name': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Index Name', y='Articles', \n       title='Number of Articles per each Index Name', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:04:45.454734Z","iopub.execute_input":"2022-02-13T07:04:45.45503Z","iopub.status.idle":"2022-02-13T07:04:45.558133Z","shell.execute_reply.started":"2022-02-13T07:04:45.454999Z","shell.execute_reply":"2022-02-13T07:04:45.557427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"garment_group_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Garment Group Name': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Garment Group Name', y='Articles', \n       title='Number of Articles per each Garment Group Name', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:05:31.780839Z","iopub.execute_input":"2022-02-13T07:05:31.781125Z","iopub.status.idle":"2022-02-13T07:05:31.885255Z","shell.execute_reply.started":"2022-02-13T07:05:31.781094Z","shell.execute_reply":"2022-02-13T07:05:31.884314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = articles_df.groupby([\"section_name\"])[\"article_id\"].nunique()\ndf = pd.DataFrame({'Section Name': temp.index,\n                   'Articles': temp.values\n                  })\ndf = df.sort_values(['Articles'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Section Name', y='Articles', \n       title='Number of Articles per each Section Name', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:06:08.257187Z","iopub.execute_input":"2022-02-13T07:06:08.257863Z","iopub.status.idle":"2022-02-13T07:06:08.369705Z","shell.execute_reply.started":"2022-02-13T07:06:08.257823Z","shell.execute_reply":"2022-02-13T07:06:08.368563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_wordcloud(articles_df[\"detail_desc\"], \"Wordcloud from detailed description of articles\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:07:05.560877Z","iopub.execute_input":"2022-02-13T07:07:05.561181Z","iopub.status.idle":"2022-02-13T07:07:06.314048Z","shell.execute_reply.started":"2022-02-13T07:07:05.561149Z","shell.execute_reply":"2022-02-13T07:07:06.313096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Customers data","metadata":{}},{"cell_type":"code","source":"temp = customers_df.groupby([\"age\"])[\"customer_id\"].count()\ndf = pd.DataFrame({'Age': temp.index,\n                   'Customers': temp.values\n                  })\ndf = df.sort_values(['Age'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Age', y='Customers', \n       title='Number of Customers per each Age', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:09:23.590796Z","iopub.execute_input":"2022-02-13T07:09:23.59109Z","iopub.status.idle":"2022-02-13T07:09:23.840008Z","shell.execute_reply.started":"2022-02-13T07:09:23.591059Z","shell.execute_reply":"2022-02-13T07:09:23.838984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = customers_df.groupby([\"fashion_news_frequency\"])[\"customer_id\"].count()\ndf = pd.DataFrame({'Fashion News Frequency': temp.index,\n                   'Customers': temp.values\n                  })\ndf = df.sort_values(['Customers'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Fashion News Frequency', y='Customers', \n       title='Number of Customers per each Fashion News Frequency', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:10:06.272946Z","iopub.execute_input":"2022-02-13T07:10:06.273468Z","iopub.status.idle":"2022-02-13T07:10:06.637367Z","shell.execute_reply.started":"2022-02-13T07:10:06.273434Z","shell.execute_reply":"2022-02-13T07:10:06.636451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = customers_df.groupby([\"club_member_status\"])[\"customer_id\"].count()\ndf = pd.DataFrame({'Club Member Status': temp.index,\n                   'Customers': temp.values\n                  })\ndf = df.sort_values(['Customers'], ascending=False)\n\n# Plotly code\npx.bar(df, x='Club Member Status', y='Customers', \n       title='Number of Customers per each Club Member Status', \n      )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:10:46.584942Z","iopub.execute_input":"2022-02-13T07:10:46.58527Z","iopub.status.idle":"2022-02-13T07:10:46.951908Z","shell.execute_reply.started":"2022-02-13T07:10:46.585235Z","shell.execute_reply":"2022-02-13T07:10:46.950877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Transactions data","metadata":{}},{"cell_type":"code","source":"df = transactions_train_df.sample(100_000)\n\n# Plotly Code\nhist_data = [\n    np.log(df.loc[df[\"sales_channel_id\"]==1].price.value_counts()), \n    np.log(df.loc[df[\"sales_channel_id\"]==2].price.value_counts())\n]\n\ngroup_labels = ['Sales channel 1', 'Sales channel 2']\n\nfig=ff.create_distplot(hist_data, \n                       group_labels, \n                       show_hist=False)\nfig.update_layout(title_text='Logaritmic distribution of price frequency in transactions, \\ngrouped per sales channel (100k sample)',\n                  xaxis_title='Price',\n                  yaxis_title='Density',\n                 )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:21:51.816038Z","iopub.execute_input":"2022-02-13T07:21:51.816494Z","iopub.status.idle":"2022-02-13T07:21:53.735785Z","shell.execute_reply.started":"2022-02-13T07:21:51.816456Z","shell.execute_reply":"2022-02-13T07:21:53.734835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = transactions_train_df.sample(100_000).groupby([\"t_dat\"])[\"article_id\"].count().reset_index()\ndf[\"t_dat\"] = df[\"t_dat\"].apply(lambda x: datetime.strptime(x, '%Y-%m-%d'))\ndf.columns = [\"Date\", \"Transactions\"]\n\n# Plotly Code\npx.line(df, x='Date', y='Transactions',\n        title='Transactions per day (100k sample)',\n       )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:25:25.583834Z","iopub.execute_input":"2022-02-13T07:25:25.584117Z","iopub.status.idle":"2022-02-13T07:25:27.529805Z","shell.execute_reply.started":"2022-02-13T07:25:25.584086Z","shell.execute_reply":"2022-02-13T07:25:27.52903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = transactions_train_df.sample(100_000).groupby([\"t_dat\", \"sales_channel_id\"])[\"article_id\"].count().reset_index()\ndf[\"t_dat\"] = df[\"t_dat\"].apply(lambda x: datetime.strptime(x, '%Y-%m-%d'))\ndf.columns = [\"Date\", \"Sales Channel Id\", \"Transactions\"]\n\n# Plotly Code\npx.line(df, x='Date', y='Transactions',\n        color='Sales Channel Id',\n        title='Transactions per day, grouped by Sales Channel (100k sample)',\n       )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:25:31.429734Z","iopub.execute_input":"2022-02-13T07:25:31.430575Z","iopub.status.idle":"2022-02-13T07:25:33.445434Z","shell.execute_reply.started":"2022-02-13T07:25:31.430518Z","shell.execute_reply":"2022-02-13T07:25:33.444287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = transactions_train_df.groupby([\"t_dat\", \"sales_channel_id\"])[\"article_id\"].nunique().reset_index()\ndf[\"t_dat\"] = df[\"t_dat\"].apply(lambda x: datetime.strptime(x, '%Y-%m-%d'))\ndf.columns = [\"Date\", \"Sales Channel Id\", \"Unique Articles\"]\n\n# Plotly Code\npx.line(df, x='Date', y='Unique Articles',\n        color='Sales Channel Id',\n        title='Unique articles per day, grouped by Sales Channel',\n       )","metadata":{"execution":{"iopub.status.busy":"2022-02-13T07:26:36.84916Z","iopub.execute_input":"2022-02-13T07:26:36.849487Z","iopub.status.idle":"2022-02-13T07:26:53.705119Z","shell.execute_reply.started":"2022-02-13T07:26:36.849454Z","shell.execute_reply":"2022-02-13T07:26:53.704061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Image data\n\n<img src=\"https://images.unsplash.com/photo-1575729312527-1bdecaae271e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=687&q=80\" width=400></img>\n\nThere are 105542 articles and 105100 different images. Let's check first which articles does not have corresponding images.\n\nThe `article_id` corresponds to digits from 2nd to the last of the image name. \nThe digits from 2nd to 7th of image name  correspond to product code (`product_code`). ","metadata":{}},{"cell_type":"code","source":"image_name_df = pd.DataFrame(images_names, columns = [\"image_name\"])\nimage_name_df[\"article_id\"] = image_name_df[\"image_name\"].apply(lambda x: int(x[1:]))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:30.334617Z","iopub.execute_input":"2022-02-13T07:27:30.33498Z","iopub.status.idle":"2022-02-13T07:27:30.448145Z","shell.execute_reply.started":"2022-02-13T07:27:30.334947Z","shell.execute_reply":"2022-02-13T07:27:30.447072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_name_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:31.721751Z","iopub.execute_input":"2022-02-13T07:27:31.722052Z","iopub.status.idle":"2022-02-13T07:27:31.733272Z","shell.execute_reply.started":"2022-02-13T07:27:31.722017Z","shell.execute_reply":"2022-02-13T07:27:31.732118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_article_df = articles_df[[\"article_id\", \"product_code\", \"product_group_name\", \"product_type_name\"]].merge(image_name_df, on=[\"article_id\"], how=\"left\")\nprint(image_article_df.shape)\nimage_article_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:32.985287Z","iopub.execute_input":"2022-02-13T07:27:32.985967Z","iopub.status.idle":"2022-02-13T07:27:33.070523Z","shell.execute_reply.started":"2022-02-13T07:27:32.985931Z","shell.execute_reply":"2022-02-13T07:27:33.069517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Products without images.","metadata":{}},{"cell_type":"code","source":"article_no_image_df = image_article_df.loc[image_article_df.image_name.isna()]\nprint(article_no_image_df.shape)\narticle_no_image_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:34.751252Z","iopub.execute_input":"2022-02-13T07:27:34.751577Z","iopub.status.idle":"2022-02-13T07:27:34.787045Z","shell.execute_reply.started":"2022-02-13T07:27:34.751543Z","shell.execute_reply":"2022-02-13T07:27:34.786313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Product codes with some missing images: \", article_no_image_df.product_code.nunique())\nprint(\"Product groups with some missing images: \", list(article_no_image_df.product_group_name.unique()))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:35.489087Z","iopub.execute_input":"2022-02-13T07:27:35.489838Z","iopub.status.idle":"2022-02-13T07:27:35.497515Z","shell.execute_reply.started":"2022-02-13T07:27:35.489802Z","shell.execute_reply":"2022-02-13T07:27:35.496444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's visualize few images.","metadata":{}},{"cell_type":"code","source":"def plot_image_samples(image_article_df, product_group_name, cols=1, rows=-1):\n    image_path = \"/kaggle/input/h-and-m-personalized-fashion-recommendations/images/\"\n    _df = image_article_df.loc[image_article_df.product_group_name==product_group_name]\n    article_ids = _df.article_id.values[0:cols*rows]\n    plt.figure(figsize=(2 + 3 * cols, 2 + 4 * rows))\n    for i in range(cols * rows):\n        article_id = (\"0\" + str(article_ids[i]))[-10:]\n        plt.subplot(rows, cols, i + 1)\n        plt.axis('off')\n        plt.title(f\"{product_group_name} {article_id[:3]}\\n{article_id}.jpg\")\n        image = Image.open(f\"{image_path}{article_id[:3]}/{article_id}.jpg\")\n        plt.imshow(image)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:36.315321Z","iopub.execute_input":"2022-02-13T07:27:36.316116Z","iopub.status.idle":"2022-02-13T07:27:36.325843Z","shell.execute_reply.started":"2022-02-13T07:27:36.316056Z","shell.execute_reply":"2022-02-13T07:27:36.325012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's choose from some product group name.","metadata":{}},{"cell_type":"code","source":"print(image_article_df.product_group_name.unique())","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:43.002166Z","iopub.execute_input":"2022-02-13T07:27:43.002746Z","iopub.status.idle":"2022-02-13T07:27:43.019943Z","shell.execute_reply.started":"2022-02-13T07:27:43.002698Z","shell.execute_reply":"2022-02-13T07:27:43.018794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We will represent images grouped on product group name.","metadata":{}},{"cell_type":"code","source":"plot_image_samples(image_article_df, \"Garment Lower body\", 4, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:43.891513Z","iopub.execute_input":"2022-02-13T07:27:43.892218Z","iopub.status.idle":"2022-02-13T07:27:46.903809Z","shell.execute_reply.started":"2022-02-13T07:27:43.892172Z","shell.execute_reply":"2022-02-13T07:27:46.902782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_samples(image_article_df, \"Stationery\", 4, 1)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:47.905244Z","iopub.execute_input":"2022-02-13T07:27:47.905812Z","iopub.status.idle":"2022-02-13T07:27:49.567572Z","shell.execute_reply.started":"2022-02-13T07:27:47.905769Z","shell.execute_reply":"2022-02-13T07:27:49.56671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_samples(image_article_df, \"Fun\", 2, 1)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T07:27:51.031631Z","iopub.execute_input":"2022-02-13T07:27:51.03214Z","iopub.status.idle":"2022-02-13T07:27:52.002937Z","shell.execute_reply.started":"2022-02-13T07:27:51.032087Z","shell.execute_reply":"2022-02-13T07:27:52.001974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_samples(image_article_df, \"Accessories\", 4, 1)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:11:40.330132Z","iopub.execute_input":"2022-02-13T05:11:40.3304Z","iopub.status.idle":"2022-02-13T05:11:42.3815Z","shell.execute_reply.started":"2022-02-13T05:11:40.330368Z","shell.execute_reply":"2022-02-13T05:11:42.380717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_samples(image_article_df, \"Swimwear\", 4, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:11:42.382607Z","iopub.execute_input":"2022-02-13T05:11:42.3834Z","iopub.status.idle":"2022-02-13T05:11:45.68876Z","shell.execute_reply.started":"2022-02-13T05:11:42.383353Z","shell.execute_reply":"2022-02-13T05:11:45.687659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_samples(image_article_df, \"Furniture\", 4, 2)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:11:45.690218Z","iopub.execute_input":"2022-02-13T05:11:45.690618Z","iopub.status.idle":"2022-02-13T05:11:49.043075Z","shell.execute_reply.started":"2022-02-13T05:11:45.690582Z","shell.execute_reply":"2022-02-13T05:11:49.042409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_samples(image_article_df, \"Cosmetic\", 4, 1)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:11:49.044221Z","iopub.execute_input":"2022-02-13T05:11:49.044515Z","iopub.status.idle":"2022-02-13T05:11:51.401526Z","shell.execute_reply.started":"2022-02-13T05:11:49.044472Z","shell.execute_reply":"2022-02-13T05:11:51.40045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_image_samples(image_article_df, \"Bags\", 4, 3)","metadata":{"execution":{"iopub.status.busy":"2022-02-13T05:11:51.40292Z","iopub.execute_input":"2022-02-13T05:11:51.403691Z","iopub.status.idle":"2022-02-13T05:11:56.327586Z","shell.execute_reply.started":"2022-02-13T05:11:51.403653Z","shell.execute_reply":"2022-02-13T05:11:56.326366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Initial submission\n\n\n<img src=\"https://images.unsplash.com/photo-1533120164489-96c6ca1f43eb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80\" width=400></img>\n\nLet's prepare a very basic initial submission.\n\nFor this initial submission, we apply the following simplified logic:\n- if there are articles for a certain client, pick the most recent buys;  \n- if there are not articles for a certain client, just pick the most frequently buyed articles.","metadata":{}},{"cell_type":"code","source":"transactions_train_df = transactions_train_df.sort_values([\"customer_id\", \"t_dat\"], ascending=False)\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:11:56.328975Z","iopub.execute_input":"2022-02-13T05:11:56.329225Z","iopub.status.idle":"2022-02-13T05:12:27.161007Z","shell.execute_reply.started":"2022-02-13T05:11:56.329189Z","shell.execute_reply":"2022-02-13T05:12:27.159869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:12:27.162404Z","iopub.execute_input":"2022-02-13T05:12:27.162659Z","iopub.status.idle":"2022-02-13T05:12:27.177018Z","shell.execute_reply.started":"2022-02-13T05:12:27.162627Z","shell.execute_reply":"2022-02-13T05:12:27.175803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's capture first what are the most frequent recently bought articles.","metadata":{}},{"cell_type":"code","source":"last_date = transactions_train_df.t_dat.max()\nprint(last_date)\nprint(transactions_train_df.loc[transactions_train_df.t_dat==last_date].shape)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:12:27.178924Z","iopub.execute_input":"2022-02-13T05:12:27.180028Z","iopub.status.idle":"2022-02-13T05:12:35.433038Z","shell.execute_reply.started":"2022-02-13T05:12:27.179971Z","shell.execute_reply":"2022-02-13T05:12:35.432096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"most_frequent_articles = list(transactions_train_df.loc[transactions_train_df.t_dat==last_date].article_id.value_counts()[0:12].index)\nart_list = []\nfor art in most_frequent_articles:\n    art = \"0\"+str(art)\n    art_list.append(art)\nart_str = \" \".join(art_list)\nprint(\"Frequent articles bought recently: \", art_str)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:12:35.435705Z","iopub.execute_input":"2022-02-13T05:12:35.436076Z","iopub.status.idle":"2022-02-13T05:12:39.661507Z","shell.execute_reply.started":"2022-02-13T05:12:35.436028Z","shell.execute_reply":"2022-02-13T05:12:39.660406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"agg_df = transactions_train_df.groupby([\"customer_id\"])[\"article_id\"].agg(lambda x: str(x.values[0:12])[1:-1]).reset_index()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:12:39.663473Z","iopub.execute_input":"2022-02-13T05:12:39.663838Z","iopub.status.idle":"2022-02-13T05:14:47.585244Z","shell.execute_reply.started":"2022-02-13T05:12:39.663789Z","shell.execute_reply":"2022-02-13T05:14:47.584339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def padding_articles(x):\n    if x:\n        xl = x.split()\n        x = []\n        for xi in xl:\n            x.append(\"0\"+xi)\n        dimm_x = len(x)\n        if dimm_x < 12:\n            x.extend(art_list[:12-dimm_x])\n        return(\" \".join(x))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:47.586685Z","iopub.execute_input":"2022-02-13T05:14:47.587028Z","iopub.status.idle":"2022-02-13T05:14:47.594546Z","shell.execute_reply.started":"2022-02-13T05:14:47.586995Z","shell.execute_reply":"2022-02-13T05:14:47.593373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"agg_df[\"article_id\"] = agg_df[\"article_id\"].apply(lambda x: padding_articles(x))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:47.596149Z","iopub.execute_input":"2022-02-13T05:14:47.596698Z","iopub.status.idle":"2022-02-13T05:14:51.771239Z","shell.execute_reply.started":"2022-02-13T05:14:47.59666Z","shell.execute_reply":"2022-02-13T05:14:51.770541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Aggregated transaction history: \", agg_df.customer_id.nunique())\nprint(\"Submission sample: \", sample_submission_df.customer_id.nunique())","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:51.772713Z","iopub.execute_input":"2022-02-13T05:14:51.773146Z","iopub.status.idle":"2022-02-13T05:14:53.743463Z","shell.execute_reply.started":"2022-02-13T05:14:51.773116Z","shell.execute_reply":"2022-02-13T05:14:53.742393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We will replace the values in sample submission with the existent in aggregated transactions data and just let the default one otherwise.","metadata":{}},{"cell_type":"code","source":"print(sample_submission_df.shape)\nsample_submission_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:53.745266Z","iopub.execute_input":"2022-02-13T05:14:53.745849Z","iopub.status.idle":"2022-02-13T05:14:53.758606Z","shell.execute_reply.started":"2022-02-13T05:14:53.7458Z","shell.execute_reply":"2022-02-13T05:14:53.757468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For the customers with missing articles, we simply replace with most frequent buyed articles in most recent day(s).","metadata":{}},{"cell_type":"code","source":"submission_df = agg_df.merge(sample_submission_df[[\"customer_id\"]], how=\"right\")\nsubmission_df.columns = [\"customer_id\", \"prediction\"]\nprint(submission_df.shape)\nsubmission_df.head()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:53.760493Z","iopub.execute_input":"2022-02-13T05:14:53.761041Z","iopub.status.idle":"2022-02-13T05:14:56.20118Z","shell.execute_reply.started":"2022-02-13T05:14:53.760994Z","shell.execute_reply":"2022-02-13T05:14:56.199973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Rows with missing data in submission: \", submission_df.loc[submission_df.prediction.isna()].shape[0])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:56.202769Z","iopub.execute_input":"2022-02-13T05:14:56.203023Z","iopub.status.idle":"2022-02-13T05:14:56.511441Z","shell.execute_reply.started":"2022-02-13T05:14:56.202991Z","shell.execute_reply":"2022-02-13T05:14:56.510223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We replace the missing data with the most frequently bought articles, from recent days. We calculated it before.","metadata":{}},{"cell_type":"code","source":"submission_df.loc[submission_df.prediction.isna(), [\"prediction\"]] = art_str","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:56.517647Z","iopub.execute_input":"2022-02-13T05:14:56.518142Z","iopub.status.idle":"2022-02-13T05:14:56.664402Z","shell.execute_reply.started":"2022-02-13T05:14:56.518106Z","shell.execute_reply":"2022-02-13T05:14:56.663392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Rows with missing data in submission: \", submission_df.loc[submission_df.prediction.isna()].shape[0])","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:56.666263Z","iopub.execute_input":"2022-02-13T05:14:56.666685Z","iopub.status.idle":"2022-02-13T05:14:56.812037Z","shell.execute_reply.started":"2022-02-13T05:14:56.666639Z","shell.execute_reply":"2022-02-13T05:14:56.81124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df.to_csv(\"submission.csv\", index=False)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-02-13T05:14:56.813261Z","iopub.execute_input":"2022-02-13T05:14:56.813747Z","iopub.status.idle":"2022-02-13T05:15:08.23546Z","shell.execute_reply.started":"2022-02-13T05:14:56.813707Z","shell.execute_reply":"2022-02-13T05:15:08.234396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}