{"cells":[{"metadata":{"_uuid":"885d77db36e54c7812fbdda86b7d6fa0b48b8f9a"},"cell_type":"markdown","source":"### Objective:\n\nThe objective of this Notebook to explore [Google Analytics Customer Revenue Prediction](https://www.kaggle.com/c/google-analytics-customer-revenue-prediction) Kaggle Competition Dataset to generate insights and finally try to predict Revenue. Quoting the organizer's words,\n\n\"Hopefully, the outcome will be more actionable operational changes and a better use of marketing budgets for those companies who choose to use data analysis on top of GA data.\"\n\n### About the Competition:\n\nIn this competition, you’re challenged to analyze a Google Merchandise Store (also known as GStore, where Google swag is sold) customer dataset to predict revenue per customer. \n\n![Competition](https://kaggle2.blob.core.windows.net/competitions/kaggle/10038/logos/header.png?t=2018-06-21-23-13-17)\n"},{"metadata":{"_uuid":"74067ed24a0dd34adaa311662c38e0efc200393d"},"cell_type":"markdown","source":"### Importing Required Libraries"},{"metadata":{"_uuid":"f96b78ecded53f1288a9698be6f09d0bb2713984","_execution_state":"idle","trusted":true},"cell_type":"code","source":"library(tidyverse) # metapackage with lots of helpful functions\nlist.files(path = \"../input\")\n#for fast EDA\nlibrary(DataExplorer) \nlibrary(ggthemes)\nlibrary(cowplot)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"27d0ac1a33a35866e8153ac5df1c82e84c5b810e"},"cell_type":"markdown","source":"### Reading Input Files"},{"metadata":{"trusted":true,"_uuid":"f2ae7c797b78fef0dbec591f7cd42a65fef665b4"},"cell_type":"code","source":"train <- read_csv(\"../input/train.csv\")\ntest <- read_csv(\"../input/test.csv\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0f957fa0f4bc2982ef931cff017198b77e37f73d"},"cell_type":"markdown","source":"### What's in the Input?"},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"dc42ed72bcebd9220b60cacdeed845a043fb109c"},"cell_type":"code","source":"glimpse(train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a266d6db62c5c01e381fc8a0fb4d054b0fb76962"},"cell_type":"code","source":"head(train,1)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d722bfdf537499da9ec88b12b374be71306cb054"},"cell_type":"markdown","source":"As you can see above, Columns like `device`, `geoNetwork`, `totals`, `trafficSource` contain `json` values. Hence those columns need to be flattened/expanded to create new columns with respective keys. \n\n\n### Expanding JSON columns in Train and Test Dataset \n\nThe solution below is from the kernel https://www.kaggle.com/mrlong/r-flatten-json-columns"},{"metadata":{"trusted":true,"_uuid":"45b195531e3c6268bb2ef1477f3d020c6d4c504e"},"cell_type":"code","source":"#Courtesy: https://www.kaggle.com/mrlong/r-flatten-json-columns\n#Courtesy: https://www.kaggle.com/mrlong/r-flatten-json-columns#387132\n\nlibrary(jsonlite)\nlibrary(rlist)\n\njsontodf <- function(col){\n    list.stack(lapply(col, function(j){\n    as.list(unlist(fromJSON(j)))}) , fill=TRUE)   \n}\n\n\n\n#Convert each JSON column in the train and test sets\ntr_device <- jsontodf(train$device)\ntr_geoNetwork <- jsontodf(train$geoNetwork)\ntr_totals <- jsontodf(train$totals)\ntr_trafficSource <- jsontodf(train$trafficSource)\n\nte_device <- jsontodf(test$device)\nte_geoNetwork <- jsontodf(test$geoNetwork)\nte_totals <- jsontodf(test$totals)\nte_trafficSource <- jsontodf(test$trafficSource)\n\n\n#Check to see if the training and test sets have the same column names\nsetequal(names(tr_device), names(te_device))\nsetequal(names(tr_geoNetwork), names(te_geoNetwork))\nsetequal(names(tr_totals), names(te_totals))\nsetequal(names(tr_trafficSource), names(te_trafficSource))\n\n#As expected, all are equal except for the totals - which includes the target, transactionRevenue\n#Clearly this should only appear in the training set\nnames(tr_totals)\nnames(te_totals)\n#transactionRevenue is the only different column here\n\n\n#Combine to make the full training and test sets\ntrain <- train %>%\n    cbind(tr_device, tr_geoNetwork, tr_totals, tr_trafficSource) %>%\n    select(-device, -geoNetwork, -totals, -trafficSource)\n    \ntest <- test %>%\n    cbind(te_device, te_geoNetwork, te_totals, te_trafficSource) %>%\n    select(-device, -geoNetwork, -totals, -trafficSource)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"ded2c2d9a6c2f0e59d57acc70b159600338b6f23"},"cell_type":"code","source":"glimpse(train)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"bc6353000b7c57f71d9944d1543d18cf32128d0e"},"cell_type":"markdown","source":"### Variable Typecasting"},{"metadata":{"trusted":true,"_uuid":"885e72eb8405c49180d43f7352c8637c7e24b779"},"cell_type":"code","source":"train$visits <- as.numeric(train$visits)\ntrain$hits <- as.numeric(train$hits)\ntrain$pageviews <- as.numeric(train$pageviews)\ntrain$bounces <- as.numeric(train$bounces)\ntrain$newVisits <- as.numeric(train$newVisits)\ntrain$transactionRevenue <- as.numeric(train$transactionRevenue)\n\n\ntest$visits <- as.numeric(test$visits)\ntest$hits <- as.numeric(test$hits)\ntest$pageviews <- as.numeric(test$pageviews)\ntest$bounces <- as.numeric(test$bounces)\ntest$newVisits <- as.numeric(test$newVisits)\n\n\ntrain$date <- as.Date(strptime(train$date, format = \"%Y%m%d\"))\ntest$date <- as.Date(strptime(test$date, format = \"%Y%m%d\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"82c4dc3828e702c856a71c15563be3226933988c"},"cell_type":"code","source":"head(train,2)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"750c6b4c7809f0fb2c119e44d033f314bc13040a"},"cell_type":"markdown","source":"### Missing Values Percentage"},{"metadata":{"trusted":true,"_uuid":"e5f93638cda0289e6ef5eb7bec49e272ce74d427"},"cell_type":"code","source":"plot_missing(train)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a525726e3b5f0fe92f0d1f2bed6826d30843fc6f"},"cell_type":"markdown","source":"### Frequency Distribution Analysis"},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"61e0f2513a177ed1b7087189c9dca4f639ac0286"},"cell_type":"code","source":"options(repr.plot.width=12)\nplot_density(train, title = \"Frequency Distribution Analysis\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"362cfd0f63949a23975712f01d1542daed2cdc54"},"cell_type":"markdown","source":"### Target Variable Frequency Distribution"},{"metadata":{"trusted":true,"_uuid":"d72069f16f6d61e1888a5f18553f11516e990e87"},"cell_type":"code","source":"library(cowplot)\n\ntrain  %>% \nggplot() + geom_density(aes(as.numeric(transactionRevenue))) +\nlabs(x = \"transactionRevenue\",\n    title = \"Frequency Distribution of transactionRevenue\") +\ntheme_minimal() -> p1\n\ntrain  %>% \nggplot() + geom_density(aes(log(as.numeric(transactionRevenue)))) +\nlabs(x = \"transactionRevenue\",\n    title = \"Frequency Distribution of Natural Log transactionRevenue\") +\ntheme_minimal() -> p2\n\nplot_grid(p1,p2)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0b95bbacf5b172a17c5fb320649884ab2e148a85"},"cell_type":"markdown","source":"### Discrete Variables Analysis "},{"metadata":{"trusted":true,"_uuid":"2bf5aadd85989289206b616d2bb35ce7fe2ec8ea"},"cell_type":"code","source":"#options(repr.plot.width=12)\n#plot_bar(train)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a355a7305e8dd5e46efd8a7c23d0521d908be1ca"},"cell_type":"markdown","source":"### GA Digital Analytics Metrics"},{"metadata":{"_uuid":"299ef62f19531501e049cc954d295c17d57d7b20"},"cell_type":"markdown","source":"At this point, you might have seen a few variables like Visits with values 1 and then Hits and Unique Visitors. These are very commonly used `Metrics` from Digital Analyics - espcially in our case in Google Analytics. Getting better understanding of the given data will always help in better **feature engineering**. Hence the following:\n\nTo start, Like any Data Visualization tool - GA has two primary components - **Dimensions** and **Metrics**.\n\n**Dimension:**\n\nA Dimension is a descriptive attribute that can be ascribed values.\n\n**Metrics**\n\nMetrics are the measurable values of that attribute. \n\n- [Reference](https://www.epa.gov/sites/production/files/documents/glossary_of_metrics_used_in_google_analytics.pdf)\n\nBelow pictures will explain the definition of a few key (aka Vanity) Metrics. Please note the metric - **Visit** is also known as **Session**, so a **new Session** means a **new Visit**. \n\n![GA Defintion](https://wpengine.com/wp-content/uploads/2017/11/common-google-analytics-metrics.png)\n\n![GA Definition #2](https://wpengine.com/wp-content/uploads/2017/11/commondefinitions.png)\n\n![GA Chart](https://wpengine.com/wp-content/uploads/2017/11/Google-Analytics_3.png)\n\n"},{"metadata":{"_uuid":"1c91de164ad5b08c0632132c2f959d93f0da1a7e"},"cell_type":"markdown","source":""},{"metadata":{"_uuid":"7171e3437a5fa3e98c4520ad07fab9e0b899e460"},"cell_type":"markdown","source":"For more verbose: https://wpengine.com/blog/the-ins-and-outs-of-google-analytics/ "},{"metadata":{"_uuid":"c04fd57b46068767f65cd1b361b1e089a020cd85"},"cell_type":"markdown","source":"### TL;DR"},{"metadata":{"_uuid":"2262ec868f038a7ab4bdab53fadaa2f3c5a626d1"},"cell_type":"markdown","source":"\nAs you can see above,\n\n**1 Visitor** (a human) can have **mutliple (n) visits or sessions** and **1 visit** can have **multiple pageviews** and if the pageview of that visit is just 1 (pageview == 1) then it's a **bounce** (which as a side note, Google considers seriously in updating Page rank). "},{"metadata":{"_uuid":"4955ead4f635b7f19bc5d88d5171c855716a587b"},"cell_type":"markdown","source":"With the above undersanding of Google Analytics and the data structure, we can see that we need to aggregate this raw data into the dimension of our desire. So, let's start aggregating with `date`"},{"metadata":{"_uuid":"6413096b76faf0ac2f6edeacf96727709c324ecf"},"cell_type":"markdown","source":"### Date wise Aggregation"},{"metadata":{"_uuid":"e7dbcfab718d8f75ba65fc908c24f33273c9c982","trusted":true},"cell_type":"code","source":"date_wise <- train  %>% \ngroup_by(date)  %>% \nsummarise(daily_visits = sum(visits, na.rm = TRUE),\ndaily_hits = sum(hits, na.rm = TRUE),\ndaily_pageviews = sum(pageviews, na.rm = TRUE),\ndaily_bounces = sum(bounces, na.rm = TRUE),\ndaily_newVisits = sum(newVisits, na.rm = TRUE),\ndaily_transactionRevenue = sum(transactionRevenue, na.rm =TRUE)\n         )","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"154352a936793169c5c61a3fe80917fa9c610d1d"},"cell_type":"code","source":"ggplot(date_wise,aes(date,daily_visits)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Visits Trend\",\n    x = \"Date\",\n    y = \"Daily Visits\") +\ngeom_smooth() -> p1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"001018e506a9982cff8f149423c55516afc07fb3"},"cell_type":"code","source":"ggplot(date_wise,aes(date,daily_hits)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Hits Trend\",\n    x = \"Date\",\n    y = \"Daily Hits\") +\ngeom_smooth() -> p2","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"24c72d48c6819e6bf046c0456bda9e196223825b"},"cell_type":"code","source":"ggplot(date_wise,aes(date,daily_newVisits)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily new Visits Trend\",\n    x = \"Date\",\n    y = \"Daily new Visits\") +\ngeom_smooth() -> p3","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4a8511eff2b26ce01d1dad19c26efe3520cf5174"},"cell_type":"code","source":"ggplot(date_wise,aes(date,daily_bounces)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Bounces Trend\",\n    x = \"Date\",\n    y = \"Daily Bounces\") +\ngeom_smooth() -> p4","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"721e7e1a357ffed82116a99715dc7b8ed9c0581d"},"cell_type":"code","source":"plot_grid(p1,p2,p3,p4, ncol = 2)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7c723e5cd79f0e85327e7c5d83738cfceeed2b39"},"cell_type":"markdown","source":"Plain `bounce` might not be entirely useful, hence let's couple it with another useful GA metric - **Bounce Rate**"},{"metadata":{"trusted":true,"_uuid":"56ebb749678f2ea696995d5b59c8322574423080"},"cell_type":"code","source":"date_wise$daily_bouncerate <- (date_wise$daily_bounces / date_wise$daily_visits) * 100","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e46ebcc8b1b9ff63b8a0cb57bf3a8ea887439179"},"cell_type":"code","source":"ggplot(date_wise,aes(date,daily_bouncerate)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Bounce Rate Trend\",\n     subtitle = \"Bounce Rate = Bounces / Visits \",\n    x = \"Date\",\n    y = \"Daily Bounce Rate in %\") +\ngeom_smooth()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"43ccc90d95e8873eee024a7d0f58ac8cbba48546"},"cell_type":"code","source":"ggplot(date_wise,aes(date,daily_transactionRevenue)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Transaction Revenue Trend\",\n     #subtitle = \"Bounce Rate = Bounces / Visits \",\n    x = \"Date\",\n    y = \"Daily Transaction Revenue\") +\ngeom_smooth() -> p1\n\nggplot(date_wise,aes(date,log(daily_transactionRevenue))) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Log Transaction Revenue Trend\",\n     #subtitle = \"Bounce Rate = Bounces / Visits \",\n    x = \"Date\",\n    y = \"Daily Log Transaction Revenue\") +\ngeom_smooth() -> p2\n\nplot_grid(p1,p2)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"03876ef8c8754b78edc287aaeee1e33fce20448d"},"cell_type":"markdown","source":"### Now, Let's replicate the same for Test Data"},{"metadata":{"trusted":true,"_uuid":"6ad77f529e981fc8ef545591d98247d309925a2c"},"cell_type":"code","source":"date_wise_test <- test  %>% \ngroup_by(date)  %>% \nsummarise(daily_visits = sum(visits, na.rm = TRUE),\ndaily_hits = sum(hits, na.rm = TRUE),\ndaily_pageviews = sum(pageviews, na.rm = TRUE),\ndaily_bounces = sum(bounces, na.rm = TRUE),\ndaily_newVisits = sum(newVisits, na.rm = TRUE)\n         )","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"de4c4e728c37ee562759adb02da407f37f749b9a"},"cell_type":"code","source":"ggplot(date_wise_test,aes(date,daily_visits)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Visits Trend\",\n    x = \"Date\",\n    y = \"Daily Visits\") +\ngeom_smooth() -> p1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"81b9c50662dcbe7325074431f9cbd708bf7afa1b"},"cell_type":"code","source":"ggplot(date_wise_test,aes(date,daily_hits)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Hits Trend\",\n    x = \"Date\",\n    y = \"Daily Hits\") +\ngeom_smooth() -> p2","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d0e2ef6c2a9a95802e73f0a5119992c72b1c2590"},"cell_type":"code","source":"ggplot(date_wise_test,aes(date,daily_newVisits)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily new Visits Trend\",\n    x = \"Date\",\n    y = \"Daily new Visits\") +\ngeom_smooth() -> p3","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"adbe5728ae20745d3578b99ab7b9483eb0d138df"},"cell_type":"code","source":"ggplot(date_wise_test,aes(date,daily_bounces)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Bounces Trend\",\n    x = \"Date\",\n    y = \"Daily Bounces\") +\ngeom_smooth() -> p4","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"efc8988efe09620608da6c61f25ddbbc60498531"},"cell_type":"code","source":"plot_grid(p1,p2,p3,p4, ncol = 2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7d337bc3be88a58c752cd6572791acba648a1270"},"cell_type":"code","source":"date_wise_test$daily_bouncerate <- (date_wise_test$daily_bounces / date_wise_test$daily_visits) * 100","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0b8e1944e0ee675ab36503c6c3f8ed71db4230ef"},"cell_type":"code","source":"ggplot(date_wise_test,aes(date,daily_bouncerate)) + geom_line() +\ntheme_economist() +\nlabs(title = \"Daily Bounce Rate Trend\",\n     subtitle = \"Bounce Rate = Bounces / Visits \",\n    x = \"Date\",\n    y = \"Daily Bounce Rate in %\") +\ngeom_smooth()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"416e9fc6b9fa58eb2d74aabb3194debb9385c337"},"cell_type":"markdown","source":"Let's move to Log as we have to predict Log of Revenue and some naive feature engineering"},{"metadata":{"trusted":true,"_uuid":"93821dea43c7699ef252af5a03d211ab0547a5ff"},"cell_type":"code","source":"train$transactionRevenue[is.na(train$transactionRevenue)] <- 0\n\ntrain$log_revenue <- log1p(train$transactionRevenue)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a1a47445cd02714fefacf33025ff524ba9e337ea"},"cell_type":"markdown","source":"### feature engineering"},{"metadata":{"trusted":true,"_uuid":"61df062a43faa320d80d2b9af71ce519412e79cc"},"cell_type":"code","source":"\ntrain$dayofweek <- weekdays(train$date)\ntrain$month <- months.Date(train$date)\ntrain$operatingSystem <- ifelse(train$operatingSystem %in% c(\"Android\",\"Macintosh\",\"Linux\",\n                                                             \"Windows\",\"iOS\",\"Chrome OS\"),\n                                train$operatingSystem,\n                                \"Others\")\n\ntrain$operatingSystem <- ifelse(train$operatingSystem %in% c(\"Android\",\"Macintosh\",\"Linux\",\n                                                             \"Windows\",\"iOS\",\"Chrome OS\"),\n                                train$operatingSystem,\n                                \"Others\")\n\ntest$dayofweek <- weekdays(test$date)\ntest$month <- months.Date(test$date)\n\ntest$operatingSystem <- ifelse(test$operatingSystem %in% c(\"Android\",\"Macintosh\",\"Linux\",\n                                                             \"Windows\",\"iOS\",\"Chrome OS\"),\n                                test$operatingSystem,\n                                \"Others\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"180db3b0afe7853ad8765c0c5b3d4713c6d8c3d4"},"cell_type":"code","source":"library(dummies)\n\ntrain <- cbind(train, dummy(train$channelGrouping), dummy(train$isMobile), dummy(train$region),\n               dummy(train$operatingSystem))\n#train$isMobile <- as.numeric(train$isMobile)\n\n\ntest$dayofweek <- weekdays(test$date)\ntest$month <- months.Date(test$date)\n\ntest$operatingSystem <- ifelse(test$operatingSystem %in% c(\"Android\",\"Macintosh\",\"Linux\",\n                                                             \"Windows\",\"iOS\",\"Chrome OS\"),\n                                test$operatingSystem,\n                                \"Others\")\n\n\ntest <- cbind(test, dummy(test$channelGrouping), dummy(test$isMobile), dummy(test$region),\n               dummy(test$operatingSystem))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"5da7720795fc8ad643b4841c13bad9f0a654c2cc"},"cell_type":"markdown","source":"Beginning our Modelling Journey with the effective H2O "},{"metadata":{"trusted":true,"_uuid":"72802c904a0f5bae904b4faa43b898e08d335773"},"cell_type":"code","source":"library(h2o)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8ad33602b2575a1caa18ddd10a54c143c28a6163"},"cell_type":"code","source":"h2o.init(nthreads=-1,max_mem_size='10G')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b4921fe673ae6d639c2af5eccd2265c4944577ef"},"cell_type":"code","source":"x <- as.h2o(train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7154329182a1c4bf9c6d4edb43e0bed9ecaff5eb"},"cell_type":"code","source":"names(train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6d47ba2c41c860504b2c02aea75069c7b9fc38b0"},"cell_type":"code","source":"\nfeatures <- colnames(train)[!(colnames(train) %in% c(\"date\",\n                                                     \"visitStartTime\",\n                                                     \"visitEndTime\",\n                                                     \"fullVisitorId\",\n                            \n                                                     \"sessionId\",\n                                                     \"visitId\", \"flashVersion\", \"browserSize\", \"transactionRevenue\",\n                                                     #\"revenue_yes\",\n                                                    # \"channelGrouping\",\n                                                     \"log_revenue\"))]\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"083afadb4eca1f8bf4f384c6eab01e978f6b1fcd"},"cell_type":"code","source":"\nmodel <- h2o.randomForest(x=features,\n                          y=\"log_revenue\", \n                          ntrees = 50,\n                          max_depth = 30,\n                          #nbins_cats = 100,  \n                          training_frame=x)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"79a0f015aafc3a335607d6c941789e8dc36a9f8c"},"cell_type":"code","source":"summary(model)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0a7185f3054ce0f1ea790e2614102668d49d18d3"},"cell_type":"code","source":"h2o.varimp_plot(model)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"90146d3854e20237cf9b5858310c868cfb347dae"},"cell_type":"code","source":"x_text <- as.h2o(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2ede7a46b9b6b05f87f3b5ff4a0a5fa84f4c5c62"},"cell_type":"code","source":"predictions <- as.data.frame(h2o.predict(model,x_text))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e772540425fbb62f21f1daca502102212af249d2"},"cell_type":"code","source":"sample_submission <- read_csv(\"../input/sample_submission.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"da78ecb10015614829a6622b6b1699ff608da31f"},"cell_type":"code","source":"names(sample_submission)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"35eb6b2fd6b663037228fa7400ac6d18fdce65a4"},"cell_type":"code","source":"submission <- data.frame(fullVisitorId=test$fullVisitorId, PredictedLogRevenue=predictions)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"08675169aa15d93ca36c6655f7b12c9236f3e140"},"cell_type":"code","source":"names(submission) <- names(sample_submission)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1f74a8cebab01c73028c787a00ff4d2a068c8387"},"cell_type":"code","source":"submission <- submission  %>% group_by(fullVisitorId)  %>% summarise(PredictedLogRevenue = sum(PredictedLogRevenue))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"05bbb9d81262cbcbeec1aa3cafb2df0bb1a5eda5"},"cell_type":"code","source":"nrow(submission) == nrow(sample_submission)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7f7ee55dea18b020352e232aaed52f8e9fb700bf"},"cell_type":"code","source":"write.csv(submission, \"ga_pred_h2o_rf.csv\",row.names=F)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f74cd104c94cfacfb8d2cbcf051fd609873244a5"},"cell_type":"markdown","source":"Work in progress!"},{"metadata":{"trusted":true,"_uuid":"aaa37766631a0c5885943bb8f34b0a35ac7ac0cd"},"cell_type":"code","source":"","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}