{"cells":[{"metadata":{"_uuid":"962d8273287bf0265f67e1722775240ae2f4622b"},"cell_type":"markdown","source":""},{"metadata":{"_uuid":"23a7811991dc8c4d7ac8b872fb7610929a4d7d41"},"cell_type":"markdown","source":"## About this notebook"},{"metadata":{"_uuid":"d1a976283c52c4585f1dc5999d0a6555e81d20b7"},"cell_type":"markdown","source":" Elo, one of the largest payment brands in Brazil, has built partnerships with merchants in order to offer promotions or discounts to cardholders. In this competition, Kagglers will develop algorithms to identify and serve the most relevant opportunities to individuals, by uncovering signal in customer loyalty. \n \n In this kernel, I have done exploratory data analysis of competetion data. This is my first R notebook. So any suggestions for improvments are welcome. **Please upvote/comment if you like it**.\n \n Reference - [https://www.kaggle.com/kailex/tidy-elo-starter-3-70/](https://www.kaggle.com/kailex/tidy-elo-starter-3-70/)\n \n *Update 1 - updated with xgboost model!"},{"metadata":{"_uuid":"2556627071aad28e16a6e94070215a74acbf70fc","_execution_state":"idle","trusted":true},"cell_type":"code","source":"## Importing libraries\nlibrary(tidyverse) # metapackage with lots of helpful functions\nlibrary(cowplot)\nlibrary(lubridate)\nlibrary(caret)\nlibrary(xgboost)\nlist.files(path = \"../input\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7edbdf85dfc018fe67d92eee140a9fe25950c99f"},"cell_type":"markdown","source":"## Import data"},{"metadata":{"trusted":true,"_uuid":"2bf36548f5423cd2da2775fd259bd47c1ebffcff"},"cell_type":"code","source":"hist.tx <- read_csv('../input/historical_transactions.csv')\nmerchants <- read_csv('../input/merchants.csv')\nnew.tx <- read_csv('../input/new_merchant_transactions.csv')\ntrain <- read_csv('../input/train.csv')\ntest <- read_csv('../input/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"382eba7772df8f17076fdc6e4028ce89f2197cdc"},"cell_type":"markdown","source":"## Exploratory Data Analysis"},{"metadata":{"trusted":true,"_uuid":"15457f7e497e6b35ac7fc9b9c84c2aed160deaab"},"cell_type":"code","source":"# data snapshot\nhead(train,5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0acf6ae3a41560d6437f3324056d310d245b2266"},"cell_type":"code","source":"print(dim(train))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"45ec08e84dbe479c9a6da92c23add9049bbefb48"},"cell_type":"markdown","source":"### Target Variable Exploration"},{"metadata":{"trusted":true,"_uuid":"03645de4662eb4d394602d69e8e887bd29816c94"},"cell_type":"code","source":"#options(repr.plot.width=4, repr.plot.height=3)\ng <- ggplot(train,aes(target)) + geom_density() #+ theme_bw(base_size=8)\nprint(g)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"bc6dc225d748d0fd4efe3afd18f2e7d4d7e9bbc1"},"cell_type":"markdown","source":"We can see that our target loyalty score is in approx. range (-10,10). Though, there are few cards which have loyalty score below -30. Let's check them."},{"metadata":{"trusted":true,"_uuid":"7c71f39562f40f0c9d8a6af8fd920f2a44341236"},"cell_type":"code","source":"count(train[train$target < -10,])","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c4bbb53d48931ebf7e18bb88b1549d01d402b28e"},"cell_type":"markdown","source":"There are 2264 such records, we would need to see how we can handle these during modelling."},{"metadata":{"_uuid":"bc69d79605e1e1ccc582a6046df171baeb2d2d68"},"cell_type":"markdown","source":"### First active month"},{"metadata":{"trusted":true,"_uuid":"a946539baa31334889331550673c55ea5886e9b1"},"cell_type":"code","source":"g1 <- ggplot(train,aes(ymd(first_active_month, truncated = 1))) +\n        geom_bar(fill='orange') + xlab('First active month - year')+ ggtitle(\"training set\")\ng2 <- ggplot(test,aes(ymd(first_active_month, truncated = 1))) +\n    geom_bar(fill='dodgerblue')+ xlab('First active month - year')+ ggtitle(\"test set\")\nprint(plot_grid(g1,g2,nrow=2,ncol=1)) ","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true,"_uuid":"1622c09c3366b2e2a583b54e0bb964a22afa5916"},"cell_type":"code","source":"rm(g1,g2); gc();","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"646ff4451cf1948d8737043ae946e36cc896b90a"},"cell_type":"markdown","source":"Most the cards in both training and test dataset were first active after 2016."},{"metadata":{"_uuid":"ccdd821045639c2475c97b8e32372b7492c4f9db"},"cell_type":"markdown","source":"### Feature1, 2 & 3"},{"metadata":{"trusted":true,"_uuid":"916b43863dcafd81083694425553c16da2cb7c1a"},"cell_type":"code","source":"#change datatype of columns feature3 to integer\ntrain$feature_3 <- as.factor(train$feature_3)\ntest$feature_3 <- as.factor(test$feature_3)\n#\n#xtick <- c(0,1)\ng1 <- ggplot(train,aes(feature_1)) + geom_bar(fill='steelblue')\ng2 <- ggplot(train,aes(feature_2)) + geom_bar(fill='steelblue')\ng3 <- ggplot(train,aes(feature_3)) + geom_bar(fill='steelblue') #+ scale_x_discrete(labels = xtick)\n\ng4 <- ggplot(test,aes(feature_1)) + geom_bar(fill='indianred')\ng5 <- ggplot(test,aes(feature_2)) + geom_bar(fill='indianred')\ng6 <- ggplot(test,aes(feature_3)) + geom_bar(fill='indianred') #+ scale_x_discrete(labels = xtick)\n\nt1 <- ggdraw() + draw_label(\"Training\")\ntr <- plot_grid(g1,g2,g3,align = 'h',ncol=3,nrow=1) #+ theme(base_size=7)\ntr1 <- plot_grid(t1,tr,ncol=1, rel_heights=c(0.1, 1))\n\nt2 <- ggdraw() + draw_label(\"Test\")\nte <- plot_grid(g4,g5,g6,align = 'h',ncol=3,nrow=1)\nte1 <- plot_grid(t2,te,ncol=1, rel_heights=c(0.1, 1))\nprint(plot_grid(tr1,te1,align='v',ncol=1,nrow=2))","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true,"_uuid":"178bc6bdd1365a08a214fd6db4098931cd608017"},"cell_type":"code","source":"rm(g1,g2,g3,g4,g5,g6,t1,tr,tr1,t2,te,te1); gc();","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d1df699e82bebbc5cdd83feca8cbb84e6bfbb043"},"cell_type":"markdown","source":"Distribution of feature_1,feature_2 and feature_3 is almost similar in training and test dataset."},{"metadata":{"_uuid":"63e6c3b254badc63d5ee1b24401c9ff202753625"},"cell_type":"markdown","source":"## Merchants"},{"metadata":{"_uuid":"4926c470a06ffefda7e2d6bf1fa31853cfe21f85"},"cell_type":"markdown","source":"Merchant count is almost idential in both columns. Most of merchants belongs to category E as per recent purchases and sales. "},{"metadata":{"trusted":true,"_uuid":"a92e3dff84d2a4b9ab234585396f106ae091b2f5"},"cell_type":"code","source":"g1 <- ggplot(merchants,aes(x = factor(1), fill = factor(category_1))) + \n        geom_bar() +coord_polar(theta = \"y\") + theme_void() +labs(fill=\"category_1\")\ng2 <- ggplot(merchants,aes(x = factor(1), fill = factor(category_4))) + \n        geom_bar() +coord_polar(theta = \"y\") + theme_void() +labs(fill=\"category_4\")\ng3 <- ggplot(merchants,aes(as.character(category_2))) + \n        geom_bar((aes(y = (..count..)/sum(..count..))),fill='steelblue') + \n        scale_y_continuous(labels = function(x) paste0(x*100, \"%\")) +\n        theme(axis.title.x = element_text(size = 11)) + \n        ylab(\"\")+xlab(\"category_2\")\n\ng4 <- ggplot(merchants,aes(most_recent_sales_range)) + geom_bar(fill='violetred') + \n        theme(axis.title.x = element_text(size = 11))\ng5 <- ggplot(merchants,aes(most_recent_purchases_range)) + geom_bar(fill='forestgreen') +\n        theme(axis.title.x = element_text(size = 11))\n\nmcat1 <- plot_grid(g1,g2,align='v',nrow=2,ncol=1)\nmcat2 <-plot_grid(g3,g4,g5,align='v',nrow=3,ncol=1)\ntitle <- ggdraw() + draw_label(\"Merchants - categorical variable\")\np <- plot_grid(mcat1,mcat2,align='h',nrow=1,ncol=2)\nprint(plot_grid(title,p,ncol=1, rel_heights=c(0.1, 1)))","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true,"_uuid":"063b4061a92ae9f1f0c8b483ea93aca0fea867f2"},"cell_type":"code","source":"rm(g1,g2,g3,g4,g5,mcat1,mcat2,title,p);gc();","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"004deac79b2888d471e826c82d7684dc5eeec9cd"},"cell_type":"markdown","source":"* Merchant count is almost idential in both columns. Most of merchants belongs to category E as per recent purchases and sales. \n* Some NA(missing) values present in column category_2.\n* Most of cards have value 'N' in column category_1."},{"metadata":{"trusted":true,"_uuid":"852452263c19109eec2b49cf153d75e77d20da3c"},"cell_type":"markdown","source":"## Historical and new transactions"},{"metadata":{"trusted":true,"_uuid":"f70ca2bbb2eae10b8bc25cacf5bbf7b0c79e8f8e"},"cell_type":"markdown","source":"### Month_lag"},{"metadata":{"trusted":true,"_uuid":"01864dd06c5e2ffe9e6f419468a5294bd93efe32"},"cell_type":"code","source":"g1 <- ggplot(hist.tx,aes(month_lag)) + \n        geom_bar((aes(y = (..count..)/sum(..count..))),fill='steelblue') + \n        scale_y_continuous(labels = function(x) paste0(x*100, \"%\")) + \n        theme(axis.title.x = element_text(size = 8))+ ylab(\"\")+xlab(\"month_lag\") +\n        ggtitle('historical transactions')\n                           \ng2 <- ggplot(new.tx,aes(as.character(month_lag))) + \n        geom_bar((aes(y = (..count..)/sum(..count..))),fill='steelblue') + \n        scale_y_continuous(labels = function(x) paste0(x*100, \"%\")) + \n        theme(axis.title.x = element_text(size = 8))+ ylab(\"\")+xlab(\"month_lag\") +\n        ggtitle(\"new transactions\")\n                           \nprint(plot_grid(g1,g2,align='h',ncol=2))\nrm(g1,g2); gc();","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"84b13270713e8da56038dbf9db46da7f87d6009d"},"cell_type":"markdown","source":"* Historical transactions have month lang in range (-13,0). Around 50% of card transactions have less than -5 month lag.\n* New transactions have only either 1 or 2 month lag."},{"metadata":{"trusted":true,"_uuid":"d5ae11678c20203eff2ad050b7875a5f8fa5bb46"},"cell_type":"code","source":"# historical transactions plot\ng1 <- ggplot(hist.tx,aes(x = factor(1), fill = factor(authorized_flag))) + \n        geom_bar() +coord_polar(theta = \"y\") + theme_void() +labs(fill=\"authorized_flag\")\ng2 <- ggplot(hist.tx,aes(x = factor(1), fill = factor(category_1))) + \n        geom_bar() +coord_polar(theta = \"y\") + theme_void() +labs(fill=\"category_1\")\ng3 <- ggplot(hist.tx,aes(as.character(category_2))) + \n        geom_bar((aes(y = (..count..)/sum(..count..))),fill='steelblue') + \n        scale_y_continuous(labels = function(x) paste0(x*100, \"%\")) +\n        theme(axis.title.x = element_text(size = 11)) + \n        ylab(\"\")+xlab(\"category_2\")\ng4 <- ggplot(hist.tx,aes(as.character(category_3))) + \n        geom_bar((aes(y = (..count..)/sum(..count..))),fill='steelblue') + \n        scale_y_continuous(labels = function(x) paste0(x*100, \"%\")) +\n        theme(axis.title.x = element_text(size = 11)) + \n        ylab(\"\")+xlab(\"category_3\")\nhistp <- plot_grid(g1,g2,g3,g4,align='v',ncol=1,nrow=4,axis='l')\nhist_title <- ggdraw() + draw_label(\"Historical\")\nhist_plot <- plot_grid(hist_title,histp,ncol=1, rel_heights=c(0.1, 1))\n                           \n#new transactions plot\ng5 <- ggplot(new.tx,aes(x = factor(1), fill = factor(authorized_flag))) + \n        geom_bar() +coord_polar(theta = \"y\") + theme_void() +labs(fill=\"authorized_flag\")\ng6 <- ggplot(new.tx,aes(x = factor(1), fill = factor(category_1))) + \n        geom_bar() +coord_polar(theta = \"y\") + theme_void() +labs(fill=\"category_1\")\ng7 <- ggplot(new.tx,aes(as.character(category_2))) + \n        geom_bar((aes(y = (..count..)/sum(..count..))),fill='steelblue') + \n        scale_y_continuous(labels = function(x) paste0(x*100, \"%\")) +\n        theme(axis.title.x = element_text(size = 11)) + \n        ylab(\"\")+xlab(\"category_2\")\ng8 <- ggplot(new.tx,aes(as.character(category_3))) + \n        geom_bar((aes(y = (..count..)/sum(..count..))),fill='steelblue') + \n        scale_y_continuous(labels = function(x) paste0(x*100, \"%\")) +\n        theme(axis.title.x = element_text(size = 11)) + \n        ylab(\"\")+xlab(\"category_3\")\nnewp <- plot_grid(g5,g6,g7,g8,align='v',ncol=1,nrow=4,axis='r')\nnew_title <- ggdraw() + draw_label(\"New\")\n                           \n#final combined plot                           \nnew_plot <- plot_grid(new_title,newp,ncol=1, rel_heights=c(0.1, 1))\nprint(plot_grid(hist_plot,new_plot,ncol=2,align='h',nrow=1))","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true,"_uuid":"84dd68152f6ef78a00a2ad5bdc74c7d6fa747f9c"},"cell_type":"code","source":"rm(g1,g2,g3,g4,g5,g6,g7,g8,histp,hist_title,hist_plot,newp,new_title,new_plot); gc();","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"75edc2db9e254b9b8b60ef5a11dd1224b176ccca"},"cell_type":"markdown","source":"## Pre-processing"},{"metadata":{"_uuid":"1a89077d9694e6efe2328eeefc87f5d335813cab"},"cell_type":"markdown","source":"### Historical"},{"metadata":{"_kg_hide-output":true,"trusted":true,"_uuid":"7488f96cb6ee0fb1200d2f44a2612847ce857488"},"cell_type":"code","source":"#preprocessing historical transactions\ncat('preprocessing historical transactions')\nhist.tx$category_2 <- as.character(hist.tx$category_2)\n#one-hot encoding of categorical variable\n#NOTE - na.action in below is needed otherwise kernel would crash due to memory limit\ndmy <- dummyVars( ~ authorized_flag+category_3+category_2,sep='_',data = hist.tx,\n                 fullRank=TRUE,na.action=NULL)\n\ndumy_hist <- data.frame(predict(dmy,newdata=hist.tx))\n\n#bind one-hot encoding columns\nfn <- funs(mean, sd, min, max, sum, n_distinct, .args = list(na.rm = TRUE))\nhist_tx <- hist.tx %>%\n    rename(card = card_id) %>%\n    bind_cols(dumy_hist) %>%\n    select(-c(authorized_flag,category_3,category_2,category_1),\n           -ends_with(\"_id\")) %>%\n    add_count(card) %>%\n    group_by(card) %>%\n    mutate(date_diff = as.integer(diff(range(purchase_date))),\n         prop = n() / sum(n)) %>% \n    ungroup() %>%\n    mutate(year = year(purchase_date),\n    month = month(purchase_date),\n    day = day(purchase_date),\n    hour = hour(purchase_date),\n    month_diff = as.integer(ymd(Sys.Date()) - date(purchase_date)) / 30 + month_lag) %>%\n    select(-purchase_date)\n\n#counts of one_hot encoded columns\ncount_hist <- hist_tx %>%\n    group_by(card) %>%\n    summarise_at(vars(c(starts_with(\"authorized_\"),starts_with(\"category_\"))),sum,\n                 na.rm = TRUE) %>%\n    rename_at(vars(-card), ~ paste0(., \"_sum\"))\n\n#distinct values of columns ending with _id(these columns are not one-hot encoded )\ndist_id_hist <- hist.tx %>%\n    rename(card=card_id) %>%\n    select(card,ends_with(\"id\")) %>%\n    group_by(card) %>%\n    summarise_at(vars(ends_with(\"id\")),n_distinct,na.rm=TRUE) %>%\n    rename_at(vars(-card), ~ paste0(., \"_n_distinct\"))\n\n#aggregation and combining above dataframes\nagg_hist <- hist_tx %>%\n    group_by(card) %>%\n    summarise_at(vars(-c(starts_with(\"authorized_\"),starts_with(\"category_\"),card)),fn,na.rm = TRUE) %>%\n    left_join(by = 'card',count_hist) %>%\n    left_join(by = 'card',dist_id_hist)\n\nrm(hist.tx,hist_tx,dmy,dumy_hist,count_hist, dist_id_hist); gc()\n\nhead(agg_hist)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8aba75bdbcf6490e7faf78254f2e191911ca61d9"},"cell_type":"markdown","source":"### New transaction and merchants"},{"metadata":{"_kg_hide-output":true,"trusted":true,"_uuid":"7f039c6a3075f1f594b1d1602a7b8543db9e726b"},"cell_type":"code","source":"#preprocess new transactions and merchants\n\ncat('preprocessing new transactions and merchants')\n#remove all columns ending with _id from merchants except merchant_id\nmerchant <- merchants %>%\n    select(-ends_with(\"_id\"),merchant_id)\n\n#join merchant with new transaction dataframe\nnew_tx <- new.tx %>%\n    left_join(by='merchant_id',merchant,suffix = c(\"\",\"_m\"))\n    \ndumy_names <- new_tx %>%\n    select(starts_with(\"category_\"),starts_with(\"most_recent_\")) %>%\n    names \nf<- paste('~', paste(dumy_names,collapse = ' + '))\n\ndmy1 <- dummyVars(as.formula(f),sep='_',data = new_tx,na.action=NULL)\ndumy_new <- data.frame(predict(dmy1,newdata=new_tx))\n\n#combine with new transactions dataframe\nnew_tx1 <- new_tx %>%\n    bind_cols(dumy_new) %>%\n    select(-c(dumy_names),-ends_with(\"_id\"),card_id) %>%\n    rename(card=card_id) %>%\n    add_count(card) %>%\n    group_by(card) %>%\n    mutate(date_diff = as.integer(diff(range(purchase_date))),\n         prop = n() / sum(n)) %>% \n    ungroup() %>%\n    mutate(year = year(purchase_date),\n    month = month(purchase_date),\n    day = day(purchase_date),\n    hour = hour(purchase_date),\n    month_diff = as.integer(ymd(Sys.Date()) - date(purchase_date)) / 30 + month_lag) %>%\n    select(-purchase_date)\n\n#replace 'Y' with 1 as all values are 'Y'\nnew_tx1$authorized_flag <- 1\n\n#aggregation -sum of categorical variables\nsum_new <- new_tx1 %>%\n    group_by(card) %>%\n    summarise_at(vars(starts_with(\"category_\"),starts_with(\"most_recent_\")),\n                 sum,na.rm = TRUE) %>%\n    rename_at(vars(-card), ~ paste0(., \"_sum\"))\n\n# distinct values of columns ending with id\ndist_id_new <- new.tx %>%\n    rename(card=card_id) %>%\n    select(card,ends_with(\"id\")) %>%\n    group_by(card) %>%\n    summarise_at(vars(ends_with(\"id\")),n_distinct,na.rm=TRUE) %>%\n    rename_at(vars(-card), ~ paste0(., \"_n_distinct\"))\n\n# aggregation of numerical columns\nagg_new <- new_tx1 %>%\n    group_by(card) %>%\n    summarise_at(vars(-starts_with(\"category_\"),-starts_with(\"most_recent_\"),\n                      -authorized_flag,-card),fn,na.rm = TRUE) %>%\n    left_join(by='card',sum_new) %>%\n    left_join(by='card',dist_id_new)\n    \nrm(new.tx,new_tx,new_tx1,merchants,merchant,dumy_names,dmy1,\n   dumy_new,sum_new,dist_id_new); gc()\n\nhead(agg_new)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-output":false,"_uuid":"d62237dc74a7ce256fc9d0df9288ab8f70678e63"},"cell_type":"markdown","source":"## Model"},{"metadata":{"trusted":true,"_uuid":"6403e095d3126a75ea2b45bc2d17313f660915aa"},"cell_type":"code","source":"#prepare traning data\ncat('preparing training data')\n\ntri <- 1:nrow(train)\ny <- train$target\n\ntr_te <- train %>% \n  select(-target) %>% \n  bind_rows(test) %>%\n  rename(card = card_id) %>% \n  mutate(first_active_month = ymd(first_active_month, truncated = 1),\n         year = year(first_active_month),\n         month = month(first_active_month),\n         date_diff = as.integer(ymd(Sys.Date()) - first_active_month)) %>% \n  select(-first_active_month) %>% \n  left_join(agg_hist, by = \"card\") %>% \n  left_join(agg_new, by = \"card\") %>% \n  select(-card) %>% \n  mutate_all(funs(ifelse(is.infinite(.), NA, .))) %>% \n  select_if(~ n_distinct(.x) > 1) %>% \n  data.matrix()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c3a210c59912e42c49be6f847d57aeeb58b6ed15"},"cell_type":"code","source":"#xgboost model\ncat('executing xgboost model')\nval <- createDataPartition(y, p = 0.2, list = FALSE) #80:20 ratio\ndtrain <- xgb.DMatrix(data = tr_te[tri, ][-val, ], label = y[-val])\ndval <- xgb.DMatrix(data = tr_te[tri, ][val, ], label = y[val])\ndtest <- xgb.DMatrix(data = tr_te[-tri, ])\ncols <- colnames(tr_te)\n\n\np <- list(objective = \"reg:linear\",\n          booster = \"gbtree\",\n          eval_metric = \"rmse\",\n          nthread = 4,\n          eta = 0.02,\n          max_depth = 7,\n          min_child_weight = 100, #10\n          gamma = 0,\n          subsample = 0.85,\n          colsample_bytree = 0.8,\n          colsample_bylevel = 0.8,\n          alpha = 0,\n          lambda = 0.1)\n\nset.seed(0)\nm_xgb <- xgb.train(p, dtrain, 2000, list(val = dval), print_every_n = 100, \n                   early_stopping_rounds = 200)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ae729c54671d4ae730f189b54fed61fc484be772"},"cell_type":"code","source":"#print feature importance\ncat('print feature importance')\nxgb.importance(cols, model = m_xgb) %>% \n  xgb.ggplot.importance(top_n = 20) + theme_minimal()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8898c178216bd86e61e8752e05e23b9fcae7b720"},"cell_type":"markdown","source":"## Writing submission"},{"metadata":{"trusted":true,"_uuid":"7baf5aa8a135542572b5c16356286c759f053bf2"},"cell_type":"code","source":"#write predictions\ncat('writing final predictions')\nread_csv(\"../input/sample_submission.csv\") %>%  \n  mutate(target = predict(m_xgb, dtest)) %>%\n  write_csv(paste0(\"tidy_elo_\", round(m_xgb$best_score, 5), \".csv\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"08e30999fbd90498dfc9b3757cece1a44cd89c52"},"cell_type":"code","source":"#best model score\nm_xgb$best_score","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}