{"metadata":{"kernelspec":{"name":"ir","display_name":"R","language":"R"},"language_info":{"name":"R","codemirror_mode":"r","pygments_lexer":"r","mimetype":"text/x-r-source","file_extension":".r","version":"4.0.5"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This R environment comes with many helpful analytics packages installed\n# It is defined by the kaggle/rstats Docker image: https://github.com/kaggle/docker-rstats\n# For example, here's a helpful package to load\n\nlibrary(tidyverse) # metapackage of all tidyverse packages\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\nlist.files(path = \"../input\")\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":"051d70d956493feee0c6d64651c6a088724dca2a","_execution_state":"idle","execution":{"iopub.status.busy":"2022-03-24T06:23:42.447507Z","iopub.execute_input":"2022-03-24T06:23:42.483493Z","iopub.status.idle":"2022-03-24T06:23:43.729587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##  packages Used\nlibrary(ggplot2)\nlibrary(dplyr)\nlibrary(readr)\nlibrary(lubridate)\nlibrary(Hmisc)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles <- read.csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ncustomers <- read.csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\nt_train <- read.csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:24:05.818596Z","iopub.execute_input":"2022-03-24T06:24:05.847027Z","iopub.status.idle":"2022-03-24T06:26:53.081900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## checking the structure of t_train dataset\nstr(t_train)\n# changing t_dat column to date data type from char\nt_train$t_dat <- as.Date(as.character(t_train$t_dat, format =\"%Y-%m-%d\"))","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:27:06.376440Z","iopub.execute_input":"2022-03-24T06:27:06.378209Z","iopub.status.idle":"2022-03-24T06:27:34.315596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## further exploration of t_train\nstr(t_train)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## seperating year and month from t_dat column\nt_train$t_dat <- ymd(t_train$t_dat)\nt_train$year <- format(year(t_train$t_dat))\nt_train$month <- format(month(t_train$t_dat))","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:28:35.474522Z","iopub.execute_input":"2022-03-24T06:28:35.476762Z","iopub.status.idle":"2022-03-24T06:32:46.104088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"str(t_train)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:33:36.659227Z","iopub.execute_input":"2022-03-24T06:33:36.661242Z","iopub.status.idle":"2022-03-24T06:33:36.695540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nsummary(t_train)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"describe(t_train)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:33:49.926669Z","iopub.execute_input":"2022-03-24T06:33:49.928483Z","iopub.status.idle":"2022-03-24T06:39:06.558771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### transaction data consist of  *1362281* unique customer_id,and they have  *104547* unique article id to choose from & data is from three years 2018-2020.\n##### this data set have no missing values","metadata":{}},{"cell_type":"code","source":"## factorise data set column year \nt_train$year <- factor(t_train$year)\nt_train$month <- factor(t_train$month)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:42:52.825833Z","iopub.execute_input":"2022-03-24T06:42:52.827778Z","iopub.status.idle":"2022-03-24T06:42:55.151010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"str(t_train)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T06:43:12.013837Z","iopub.execute_input":"2022-03-24T06:43:12.015539Z","iopub.status.idle":"2022-03-24T06:43:12.044388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# checking out which is top most selling article id in 2020\nt_train2020<-t_train %>% filter(year==2020) %>% count(article_id) %>% arrange(-n)\n","metadata":{"execution":{"iopub.status.busy":"2022-03-24T07:00:25.255183Z","iopub.execute_input":"2022-03-24T07:00:25.257148Z","iopub.status.idle":"2022-03-24T07:00:29.562553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## to get to know more about the articles which  are top sellers we are merging t_train_2020 data set with articles dataset\na_t_train2020_merged <- merge(t_train2020,articles,by=\"article_id\")","metadata":{"execution":{"iopub.status.busy":"2022-03-24T07:13:07.586650Z","iopub.execute_input":"2022-03-24T07:13:07.588377Z","iopub.status.idle":"2022-03-24T07:13:07.833859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"str(a_t_train2020_merged)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T07:13:40.223857Z","iopub.execute_input":"2022-03-24T07:13:40.225873Z","iopub.status.idle":"2022-03-24T07:13:40.278869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Renaming column name \"n\" with \"total_article_sold\"","metadata":{}},{"cell_type":"code","source":"a_t_train2020_merged %>% rename(total_article_sold = n)","metadata":{"execution":{"iopub.status.busy":"2022-03-24T07:18:35.426127Z","iopub.execute_input":"2022-03-24T07:18:35.428768Z","iopub.status.idle":"2022-03-24T07:18:35.651536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### As we can see product code column is more relevant for the purpose of categorizing product by their type.","metadata":{}},{"cell_type":"code","source":"a_t_train2020_merged %>% select(-article_id) %>% group_by(product_id) %>% mutate(total_product_sold =sum(total_article_sold))","metadata":{"execution":{"iopub.status.busy":"2022-03-24T08:35:37.183235Z","iopub.execute_input":"2022-03-24T08:35:37.184705Z","iopub.status.idle":"2022-03-24T08:35:37.218948Z"},"trusted":true},"execution_count":null,"outputs":[]}]}