{"cells":[{"metadata":{"_uuid":"6cb94db85d38910dd673138acd2ed065c7cf1fad","_execution_state":"idle","trusted":true},"cell_type":"code","source":"## Importing packages\n\n# This R environment comes with all of CRAN and many other helpful packages preinstalled.\n# You can see which packages are installed by checking out the kaggle/rstats docker image: \n# https://github.com/kaggle/docker-rstats\n\nlibrary(tidyverse) # metapackage with lots of helpful functions\n\n## Running code\n\n# In a notebook, you can run a single code cell by clicking in the cell and then hitting \n# the blue arrow to the left, or by clicking in the cell and pressing Shift+Enter. In a script, \n# you can run code by highlighting the code you want to run and then clicking the blue arrow\n# at the bottom of this window.\n\n## Reading in files\n\n# You can access files from datasets you've added to this kernel in the \"../input/\" directory.\n# You can see the files added to this kernel by running the code below. \n\nlist.files(path = \"../input\")\n\n## Saving data\n\n# If you save any files or images, these will be put in the \"output\" directory. You \n# can see the output directory by committing and running your kernel (using the \n# Commit & Run button) and then checking out the compiled version of your kernel.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ae76201f656cd5e46f917ab3009be3d839589164"},"cell_type":"code","source":"library(data.table)\ntrain = fread(\"../input/preprocessing-of-the-v2-datasets/train_v2_clean.csv\", header = TRUE,\n           colClasses=c(fullVisitorId='character'))\ntest = fread(\"../input/preprocessing-of-the-v2-datasets/test_v2_clean.csv\", header = TRUE,\n           colClasses=c(fullVisitorId='character'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d621dc54809aa7b309835ef330dea631927eb3fe"},"cell_type":"code","source":"print('train:'); dim(train)\nprint('test:'); dim(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"84de90845282fb2cc60de11389ad0916a8f73bf9","_kg_hide-output":true},"cell_type":"code","source":"# correct the data types\ndata_num <- train[,c(4,17:23)]\ndata_cat <- train[,-c(4,17:23)]\ndata_cat <- data.frame(apply(data_cat, 2,function(x){as.factor(x)}))\ndata_num <- data.frame(apply(data_num, 2,function(x){as.numeric(x)}))\ntrain <- cbind(data_cat,data_num)\nstr(train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8d547e4a5db1ceb6554697dec93ea413230a0dbf","_kg_hide-output":true},"cell_type":"code","source":"library(chron)\ntrain$date <- as.Date(as.character(train$date), format= \"%Y-%m-%d\")\ntrain$dayOfMonth <- as.factor(days(train$date))\ntrain$month <- as.factor(month(train$date))\nstr(train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6d9d238bf30755ad51cd312ded4ff4bf9adffb3b"},"cell_type":"code","source":"head(train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d7a293bd99313f767ff008c3ac12b9a76e5ae6a4","_kg_hide-output":true},"cell_type":"code","source":"# correct the data types\ndata_num <- test[,c(4,17:23)]\ndata_cat <- test[,-c(4,17:23)]\ndata_cat <- data.frame(apply(data_cat, 2,function(x){as.factor(x)}))\ndata_num <- data.frame(apply(data_num, 2,function(x){as.numeric(x)}))\ntest <- cbind(data_cat,data_num)\nstr(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8970abb24716b702ae230863c8bbc5b3a5fa7326","_kg_hide-output":true},"cell_type":"code","source":"test$date <- as.Date(as.character(test$date), format= \"%Y-%m-%d\")\ntest$dayOfMonth <- as.factor(days(test$date))\ntest$month <- as.factor(month(test$date))\nstr(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fdd83fcadea6966d4506553bbdb560d58555b475"},"cell_type":"code","source":"levels(train$browser) <- c(levels(train$browser),\n                          setdiff(levels(test$browser),levels(train$browser)))\nlevels(train$operatingSystem) <- c(levels(train$operatingSystem),\n                          setdiff(levels(test$operatingSystem),levels(train$operatingSystem)))\nlevels(train$country) <- c(levels(train$country),\n                          setdiff(levels(test$country),levels(train$country)))\nlevels(train$region) <- c(levels(train$region),\n                          setdiff(levels(test$region),levels(train$region)))\nlevels(train$metro) <- c(levels(train$metro),\n                          setdiff(levels(test$metro),levels(train$metro)))\nlevels(train$city) <- c(levels(train$city),\n                          setdiff(levels(test$city),levels(train$city)))\nlevels(train$campaign) <- c(levels(train$campaign),\n                          setdiff(levels(test$campaign),levels(train$campaign)))\nlevels(train$source) <- c(levels(train$source),\n                          setdiff(levels(test$source),levels(train$source)))\nlevels(train$adContent) <- c(levels(train$adContent),\n                          setdiff(levels(test$adContent),levels(train$adContent)))\nlevels(train$adwordsClickInfo.page) <- c(levels(train$adwordsClickInfo.page),\n                          setdiff(levels(test$adwordsClickInfo.page),levels(train$adwordsClickInfo.page)))\nlevels(train$adwordsClickInfo.slot) <- c(levels(train$adwordsClickInfo.slot),\n                          setdiff(levels(test$adwordsClickInfo.slot),levels(train$adwordsClickInfo.slot)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"70132925f88080c624927a9686f115beac47e2f5"},"cell_type":"code","source":"library(DescTools)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a17094c65ed830173f99ac067c74816b081b9653"},"cell_type":"code","source":"tr <- data.frame(fullVisitorId=unique(train$fullVisitorId))\ntemp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(channelGrouping = Mode(channelGrouping)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ea85326d3e4035dd6d24ce9e4913ecc719fe68ee"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(value = Mode(value)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e0bcf756c32329b9727aeccd37f34ea525f8f0b7"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(browser = Mode(browser)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"afbe02e1c328277ae1a18e281f01a1c2ae05d4fc"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(operatingSystem = Mode(operatingSystem)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"74778d796f7c4ff1fced1df6d808c9df901d48fb"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(isMobile = Mode(isMobile)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"46138725d1e47f196758e71ab8175d2ef74a6f0e"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(deviceCategory = Mode(deviceCategory)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4f33e3cc6b00ca3e1943ec2b344334e674866c0b"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(continent = Mode(continent)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"16add8f02090c365380d6ac46a2da0b0c1b6fb55"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(subContinent = Mode(subContinent)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1c30c3fbd1c4a6377b15567b87e513fd92226a8f"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(country = Mode(country)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fcd910d9c7ec38926c8c68f6419cc901f9a8c651"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(region = Mode(region)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9b9f66b20048b7a1df43a0aa65d27bbd595bb349"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(metro = Mode(metro)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7b7799270abe24af92e17ff020f9d49d60f74ee6"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(city = Mode(city)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e08a451cd795674704c56093e49c3e9af12e4693"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(campaign = Mode(campaign)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e9201dc86679ddbb45a373a4a44f3fe2ba0015ae"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(source = Mode(source)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5235640e3d63a9fe219f29e3946fa099bb4d0836"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(medium = Mode(medium)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"470286e1669544ae49bb21c6406d13c8409c5c81"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(isTrueDirect = Mode(isTrueDirect)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3d4d46127b69dcba75d4196d6580a7bb139a19e7"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(adContent = Mode(adContent)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b51454b45824fa759abc31df18c3a9e7338725d9"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(adwordsClickInfo.page = Mode(adwordsClickInfo.page)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"32bfb8206ed8788963648d7656d06a92f860e813"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(adwordsClickInfo.slot = Mode(adwordsClickInfo.slot)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c76e5240f88cde33fe4d70ee0351c012add82d03"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(adwordsClickInfo.adNetworkType = Mode(adwordsClickInfo.adNetworkType)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3a4bfc471854845d8e77030678a27de8a114e575"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(visitNumber = last(visitNumber))\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2e44680087e5994e862841d7ec9c604d275848d4"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(hits = mean(hits))\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"11624d4b9700c1978a8d6ce57178f42b64687957"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(pageviews = mean(pageviews))\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"06129b01aa92d02438e29cdf14ad7a3ad1274531"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(sessionQualityDim = mean(sessionQualityDim))\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1fe2342315b5ed176b0aa699df952b2897d910cd"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(timeOnSite = mean(timeOnSite))\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"74a4a31fce860cf9a547521927aa22305a8a3e4e"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(transactions = sum(transactions))\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4a0a658faaa65fc222b3a1f96222773467ffcf4a"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(transactionRevenue = sum(transactionRevenue))\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bc660295ffe980b5e7300a95c262675ecf8f5fd2"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(totalTransactionRevenue = mean(totalTransactionRevenue))\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b3b20a929cfea083956d5439b7ab95c40ac2c88f"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(dayOfMonth = Mode(dayOfMonth)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6f488265c77606e1d4c562b3c1b3dbd6ef0dbc3f"},"cell_type":"code","source":"temp<-train %>%\n  group_by(fullVisitorId) %>%\n  summarise(month = Mode(month)[1])\ntr <- merge(tr,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"62018d96445f6b1985f78d0fad71e43aad274514"},"cell_type":"code","source":"# --- write to csv\nwrite.csv(tr, \"train_agg.csv\",row.names = FALSE)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e8f196f942d27daed74840d5a7184b1f9851950a"},"cell_type":"code","source":"# correct the data types\ndata_cat <- tr[,c(1:21,30,31)]\ndata_num <- tr[,-c(1:21,30,31)]\ndata_cat <- data.frame(apply(data_cat, 2,function(x){as.factor(x)}))\ndata_num <- data.frame(apply(data_num, 2,function(x){as.numeric(x)}))\ntr <- cbind(data_cat,data_num)\nstr(tr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a93d97b8fec1ebe32307deba86044673c486b772"},"cell_type":"code","source":"# Split Data into Train and test - 70:30\nlibrary(caret)\nset.seed(7)\ntrain_test_split<-createDataPartition(tr$transactionRevenue, p=0.7, list = FALSE)\ntrain_data<-tr[train_test_split,]\ntest_data<-tr[-train_test_split,]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"38feaf13751889f00fd3c2633ec817c7c74c67bb","_kg_hide-output":false},"cell_type":"code","source":"#library(rpart)\n#model <- rpart(transactionRevenue~., data=train_data[,-c(2,3,15,19,20,26)], control=rpart.control(minsplit=10))\n#summary(model)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4f905050710465fa54781493cba130cad0599112"},"cell_type":"code","source":"library(gbm)\nset.seed(7)\n# train GBM model\ngbm.fit <- gbm(\n  formula = transactionRevenue ~ .,\n  distribution = \"gaussian\",\n  data = train_data[,-c(1)],\n  n.trees = 3500,\n  interaction.depth = 5,\n  shrinkage = 0.001,\n  bag.fraction = 0.5,\n  train.fraction = 0.5,\n  n.minobsinnode = 10,\n  cv.folds = 3,\n  n.cores = NULL, # will use all cores by default\n  verbose = FALSE\n  )\nprint(gbm.fit)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8da4a88974dfdbccaf7dc96f4acf1e519e85e705"},"cell_type":"code","source":"# Check performance using 5-fold cross-validation\nbest.iter <- gbm.perf(gbm.fit, method = \"cv\")\nprint(best.iter)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0efe05bb57d894e0a7b547071e02e35e27aeb4f9"},"cell_type":"code","source":"# get MSE and compute RMSE\nsqrt(min(gbm.fit$cv.error))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9eeec3114c0a7303b97cad083c8898b4fe7bcf3c"},"cell_type":"code","source":"summary(gbm.fit)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"eacf762bb7fd2765e25e73df676abdf97826ae30"},"cell_type":"code","source":"# predict values for test split\npred <- predict(gbm.fit, n.trees = best.iter, test_data)\n# results\ncaret::RMSE(pred, test_data$transactionRevenue)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f8b324de9a5a16b92356d869b681ab1ac449ba9d"},"cell_type":"code","source":"# predict values for test data\npred <- predict(gbm.fit, n.trees = best.iter, test)\n# results\ncaret::RMSE(pred, test$transactionRevenue)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0f75fb9320cb9e86fcc517b389d3b4ff24196fd8"},"cell_type":"code","source":"test$target <- ifelse(pred<0,0,pred)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5ffa44740f1c035501b68feca4feabbd46e120f0"},"cell_type":"code","source":"tsf_data <- data.frame(fullVisitorId=unique(test$fullVisitorId))\ndim(tsf_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"706b2ee0743d14d190082e318b979c6fd6b4a4d2"},"cell_type":"code","source":"temp<-test %>%\n  group_by(fullVisitorId) %>%\n  summarise(PredictedLogRevenue = log(sum(target)+1))\ntsf_data <- merge(tsf_data,temp,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\ndim(tsf_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e6968a5f411133d6a6510e394d2e86366f71cbf7"},"cell_type":"code","source":"head(tsf_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7f3313aee691649395c4ece17ebc2b2564480f46"},"cell_type":"code","source":"submission_v2 <- read_csv('../input/ga-customer-revenue-prediction/sample_submission_v2.csv',col_names=TRUE)\nhead(submission_v2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f19b083f79344add2ca7f39612eb6fe918766073"},"cell_type":"code","source":"submission_v2<-submission_v2[,-c(2)]\nsubmission<-merge(submission_v2,tsf_data,by=\"fullVisitorId\",sort = FALSE,all.x=TRUE)\nhead(submission)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2c99e0a0453d80a30a7c31a5c383df1bcdf4a738"},"cell_type":"code","source":"# --- write to csv\nwrite.csv(submission, \"submission.csv\",row.names = FALSE)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"mimetype":"text/x-r-source","name":"R","pygments_lexer":"r","version":"3.4.2","file_extension":".r","codemirror_mode":"r"}},"nbformat":4,"nbformat_minor":1}