{"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":"# load the necessary libraries\nlibrary(tidyverse)\nlibrary(arules)","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:45:17.175894Z","iopub.execute_input":"2023-04-17T10:45:17.182531Z","iopub.status.idle":"2023-04-17T10:45:20.891385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##loading the dataset\nfiles <- list.files(path = \"../input/h-and-m-personalized-fashion-recommendations\", full.names = TRUE, pattern = \"\\\\.csv$\")","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:45:25.642938Z","iopub.execute_input":"2023-04-17T10:45:25.756845Z","iopub.status.idle":"2023-04-17T10:45:25.803182Z"},"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":"2023-04-17T10:45:45.757647Z","iopub.execute_input":"2023-04-17T10:45:45.759258Z","iopub.status.idle":"2023-04-17T10:45:52.309381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train_data <- read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:56:10.480737Z","iopub.execute_input":"2023-04-17T10:56:10.482346Z","iopub.status.idle":"2023-04-17T10:56:55.739064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## extracting 20,000 entries because the data is too big\nset.seed(123)\ntransactions_train <- transactions_train_data[sample(nrow(transactions_train_data), 20000),]","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:08.904366Z","iopub.execute_input":"2023-04-17T10:57:08.906337Z","iopub.status.idle":"2023-04-17T10:57:08.937417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_train %>% head","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:15.122161Z","iopub.execute_input":"2023-04-17T10:57:15.124557Z","iopub.status.idle":"2023-04-17T10:57:15.156338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# extracting year and month from each date and assigning it to a new variable called month\ntransactions <- transactions_train %>% mutate(month = substr(t_dat, 1, 7))","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:39.223541Z","iopub.execute_input":"2023-04-17T10:57:39.225516Z","iopub.status.idle":"2023-04-17T10:57:39.284063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#group the data by month \ntransactions %>% group_by(month) %>% summarize(n = n())","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:41.285664Z","iopub.execute_input":"2023-04-17T10:57:41.287603Z","iopub.status.idle":"2023-04-17T10:57:41.338996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Subset the 'transactions' data frame to only include rows with month equal to \"2020-09\" then Group the resulting data frame by 'article_id'.\nCalculate the number of rows (i.e., transactions) in each group using the 'n()' function\nSummarize the data by creating a new data frame that includes the 'article_id' and the corresponding count of transactions.\nSort the resulting data frame in descending order based on the count of transactions","metadata":{}},{"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":"2023-04-17T10:57:43.271567Z","iopub.execute_input":"2023-04-17T10:57:43.273840Z","iopub.status.idle":"2023-04-17T10:57:43.347904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rank_2020_09 %>% head(20)","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:45.017789Z","iopub.execute_input":"2023-04-17T10:57:45.019734Z","iopub.status.idle":"2023-04-17T10:57:45.054296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"here we take the 'rank_2020_09' data frame and select only the top 12 rows using the 'head()' function and then Extract the 'article_id' column from the resulting data frame using the 'pull()' function .\nwe Concatenate the resulting article IDs into a single character string with a space separator between them using the 'str_c()' function from stringr.\n then we Assign the resulting concatenated string of article IDs to the variable 'my_prediction'","metadata":{}},{"cell_type":"code","source":"my_prediction <- rank_2020_09 %>% head(12) %>% pull(article_id) %>% str_c(collapse = \" \")","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:46.852855Z","iopub.execute_input":"2023-04-17T10:57:46.855083Z","iopub.status.idle":"2023-04-17T10:57:46.875377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_prediction","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:48.451336Z","iopub.execute_input":"2023-04-17T10:57:48.453341Z","iopub.status.idle":"2023-04-17T10:57:48.475361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission %>% head","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:50.642633Z","iopub.execute_input":"2023-04-17T10:57:50.644762Z","iopub.status.idle":"2023-04-17T10:57:50.675878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_submission <- sample_submission %>% mutate(prediction = my_prediction)","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:53.162681Z","iopub.execute_input":"2023-04-17T10:57:53.164736Z","iopub.status.idle":"2023-04-17T10:57:53.201901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_submission %>% head","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:55.093930Z","iopub.execute_input":"2023-04-17T10:57:55.095969Z","iopub.status.idle":"2023-04-17T10:57:55.127546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_submission %>% write_csv(\"submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-04-17T10:57:59.663214Z","iopub.execute_input":"2023-04-17T10:57:59.665246Z","iopub.status.idle":"2023-04-17T10:58:00.578553Z"},"trusted":true},"execution_count":null,"outputs":[]}]}