{"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-30T00:34:02.493395Z","iopub.execute_input":"2022-03-30T00:34:02.495724Z","iopub.status.idle":"2022-03-30T00:34:03.854415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"files <- list.files(path = \"../input/h-and-m-personalized-fashion-recommendations\", full.names = TRUE, pattern = \"\\\\.csv$\")","metadata":{"execution":{"iopub.status.busy":"2022-03-30T01:21:40.729273Z","iopub.execute_input":"2022-03-30T01:21:40.731028Z","iopub.status.idle":"2022-03-30T01:21:40.745555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"files","metadata":{"execution":{"iopub.status.busy":"2022-03-30T01:21:43.424916Z","iopub.execute_input":"2022-03-30T01:21:43.426581Z","iopub.status.idle":"2022-03-30T01:21:43.445613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission <- read_csv(\"../input/h-and-m-personalized-fashion-recommendations/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:34:03.930231Z","iopub.execute_input":"2022-03-30T00:34:03.931759Z","iopub.status.idle":"2022-03-30T00:34:05.148499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train <- read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:34:05.171541Z","iopub.execute_input":"2022-03-30T00:34:05.173138Z","iopub.status.idle":"2022-03-30T00:34:17.509529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train %>% head","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:34:17.561407Z","iopub.execute_input":"2022-03-30T00:34:17.562922Z","iopub.status.idle":"2022-03-30T00:34:17.595219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions <- transactions_train %>% mutate(month = substr(t_dat, 1, 7))","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:34:17.598231Z","iopub.execute_input":"2022-03-30T00:34:17.600248Z","iopub.status.idle":"2022-03-30T00:36:57.098741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions %>% group_by(month) %>% summarize(n = n())","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:36:57.102026Z","iopub.execute_input":"2022-03-30T00:36:57.103696Z","iopub.status.idle":"2022-03-30T00:36:58.146094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rank_2020_09 <- transactions %>% filter(month == \"2020-09\") %>% group_by(article_id) %>% summarize(n = n()) %>% arrange(desc(n))","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:36:58.148638Z","iopub.execute_input":"2022-03-30T00:36:58.150139Z","iopub.status.idle":"2022-03-30T00:36:59.999833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rank_2020_09 %>% head(20)","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:37:00.002699Z","iopub.execute_input":"2022-03-30T00:37:00.004330Z","iopub.status.idle":"2022-03-30T00:37:00.037616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_prediction <- rank_2020_09 %>% head(12) %>% pull(article_id) %>% str_c(collapse = \" \")","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:37:00.041081Z","iopub.execute_input":"2022-03-30T00:37:00.043147Z","iopub.status.idle":"2022-03-30T00:37:00.068176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_prediction","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:37:00.071531Z","iopub.execute_input":"2022-03-30T00:37:00.073373Z","iopub.status.idle":"2022-03-30T00:37:00.091948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission %>% head","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:37:00.095075Z","iopub.execute_input":"2022-03-30T00:37:00.096977Z","iopub.status.idle":"2022-03-30T00:37:00.125030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_submission <- sample_submission %>% mutate(prediction = my_prediction)","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:37:00.128318Z","iopub.execute_input":"2022-03-30T00:37:00.130226Z","iopub.status.idle":"2022-03-30T00:37:00.164953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_submission %>% head","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:37:00.169735Z","iopub.execute_input":"2022-03-30T00:37:00.171876Z","iopub.status.idle":"2022-03-30T00:37:00.205363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_submission %>% write_csv(\"submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-30T00:37:00.210095Z","iopub.execute_input":"2022-03-30T00:37:00.212301Z","iopub.status.idle":"2022-03-30T00:37:05.402832Z"},"trusted":true},"execution_count":null,"outputs":[]}]}