{
  "id": 23128,
  "title": "Using split",
  "url": "/competitions/bosch-production-line-performance/discussion/23128",
  "author_name": "",
  "post_date": "2016-08-27T16:31:47.980Z",
  "votes": 5,
  "comment_count": 3,
  "views": 998,
  "content": "<p>If you have Linux, GOW (GNU on Windows), or MSYS (part of MinGW), you can use the split command from a shell to break the training and test data into manageable chunks.  The syntax is</p>\n\n<p>split -l 10000 -d -a 3 train_numeric.csv trn_num.csv</p>\n\n<p>Then, in your R or Python script, use a for loop to cycle through the chunks, and then ensemble the models to get the best fit on the test data.  Here's my first submission:</p>\n\n<pre><code># Each file is much too large to fit into memory, so they are split into groups of 10,000 at \n# the O/S level.\n#\n# split -l 10000 -d -a 3 train_numeric.csv trn_num.csv\n#\n# results in 119 files names trn_num.csv###\n# Applying the same command to the other files so each set of identically numbered files will\n# fit in memory.\n# I'll apply xgboost to each file set, and save each tree independently.  Then, I'll run each \n# test row against each tree and average the results.\n\nlibrary(xgboost)\nxgforest &lt;- list()\nimportance_matrix &lt;- list()\nallcount &lt;- 0\ntruecount &lt;- 0\nfor (ti in 0:118) {\n    cat (&quot;Training chunk #&quot;,ti)\n    if (ti==0) {\n        hdr &lt;- TRUE\n    } else {\n        hdr &lt;- FALSE\n    }\n    a &lt;- read.csv(paste(&quot;trn_num.csv&quot;,sprintf(&quot;%03d&quot;,ti),sep=''),header=hdr)\n    allcount &lt;- allcount + nrow(a)\n    truecount &lt;- truecount + sum(a$Response)\n    \tb &lt;- read.csv(paste(&quot;trn_cat.csv&quot;,sprintf(&quot;%03d&quot;,ti),sep=''),header=hdr)\n    \tlof &lt;- lapply(b,is.factor)\n    \t#b &lt;- lapply(b,function(bc) if (is.factor(bc)) { as.numeric(bc) })\n    \tfor (bc in 2:ncol(b)) if (is.factor(b[,bc])) {b[,bc]&lt;-as.numeric(b[,bc])}\n    \tc &lt;- read.csv(paste(&quot;trn_date.csv&quot;,sprintf(&quot;%03d&quot;,ti),sep=''),header=hdr)\n    \tfor (cc in 2:ncol(c)) if (is.factor(c[,cc])) {c[,cc]&lt;-as.numeric(c[,cc])}\n    \tif (ti==0) {\n    \t\tanames &lt;- names(a)\n    \t\tbnames &lt;- names(b)\n    \t\tcnames &lt;- names(c)\n    \t} else {\n    \t\tnames(a) &lt;- anames\n    \t\tnames(b) &lt;- bnames\n    \t\tnames(c) &lt;- cnames\n    \t}\n    \td &lt;- cbind(a,b,all=TRUE)\n    \td &lt;- cbind(d,c,all=TRUE)\n    \td &lt;- d[,-970] # Response\n    \tresponse &lt;- a[,c(&quot;Id&quot;,&quot;Response&quot;)]\n    \trm(a)\n    \trm(b)\n    \trm(c)\n    \tdtrain &lt;- xgb.DMatrix(as.matrix(d[,-1]),label=response$Response,missing='')\n    xgmodel &lt;- xgboost(data=dtrain,objective=&quot;binary:logistic&quot;,eta=0.09,\n            nrounds=40,max_depth=25,verbose=1)\n    importance_matrix[[ti+1]] &lt;- xgb.importance(names(d[,-1]),model=xgmodel)\n    xgforest[[ti+1]] &lt;- xgmodel\n    rm(d)\n    rm(dtrain)\n}\nout &lt;- data.frame()\ncat(truecount,&quot; / &quot;,allcount,&quot;\\n&quot;)\nfor (si in 0:118) {\n    cat(&quot;Processing submission chunk&quot;,si,&quot;\\n&quot;)\n    if (si==0) {\n        hdr &lt;- TRUE\n    } else {\n        hdr &lt;- FALSE\n    }\n    a &lt;- read.csv(paste(&quot;tst_num.csv&quot;,sprintf(&quot;%03d&quot;,si),sep=''),header=hdr)\n    b &lt;- read.csv(paste(&quot;tst_cat.csv&quot;,sprintf(&quot;%03d&quot;,si),sep=''),header=hdr)\n    lof &lt;- lapply(b,is.factor)\n    #b &lt;- lapply(b,function(bc) if (is.factor(bc)) { as.numeric(bc) })\n    for (bc in 2:ncol(b)) if (is.factor(b[,bc])) {b[,bc]&lt;-as.numeric(b[,bc])}\n    c &lt;- read.csv(paste(&quot;tst_date.csv&quot;,sprintf(&quot;%03d&quot;,si),sep=''),header=hdr)\n    for (cc in 2:ncol(c)) if (is.factor(c[,cc])) {c[,cc]&lt;-as.numeric(c[,cc])}\n    if (si==0) {\n        anames &lt;- names(a)\n        bnames &lt;- names(b)\n        cnames &lt;- names(c)\n    } else {\n        names(a) &lt;- anames\n        names(b) &lt;- bnames\n        names(c) &lt;- cnames\n    }\n    d &lt;- cbind(a,b,all=TRUE)\n    d &lt;- cbind(d,c,all=TRUE)\n    rm(a)\n    rm(b)\n    rm(c)\n    submit_mtx &lt;- matrix(nrow=nrow(d),ncol=length(xgforest)+1)\n    dsubmit &lt;- xgb.DMatrix(as.matrix(d[,-1]),missing='')\n    mctr = 1\n    for (xgmodel in xgforest) {\n        submit_mtx[,mctr] &lt;- predict(xgmodel,dsubmit)\n        mctr &lt;- mctr + 1\n    }\n    meancol &lt;- length(xgforest)+1\n    for (r in 1:nrow(d)) submit_mtx[r,meancol] &lt;- round(max(submit_mtx[r,1:meancol-1]))\n    sub &lt;- cbind(d$Id,submit_mtx[,meancol])\n    \tout &lt;- rbind(out,sub)\n    }\n    names(out) &lt;- c(&quot;Id&quot;,&quot;Response&quot;)\n    out$Id &lt;- as.integer(out$Id)\n    write.csv(out,file=&quot;bosch_submit3.csv&quot;,row.names=FALSE,quote=FALSE)\n    cat (sum(out$Response))\nimp &lt;- as.character()\nfor (i in 1:length(importance_matrix)) imp &lt;- c(imp,importance_matrix[[i]]$Feature)\nimp_table &lt;- table(imp)\nimp_table &lt;- imp_table[order(imp_table,decreasing=TRUE)]\n</code></pre>",
  "messages": [
    {
      "id": "132626",
      "postDate": "08/27/2016 16:31:47",
      "content": "<p>If you have Linux, GOW (GNU on Windows), or MSYS (part of MinGW), you can use the split command from a shell to break the training and test data into manageable chunks.  The syntax is</p>\n\n<p>split -l 10000 -d -a 3 train_numeric.csv trn_num.csv</p>\n\n<p>Then, in your R or Python script, use a for loop to cycle through the chunks, and then ensemble the models to get the best fit on the test data.  Here's my first submission:</p>\n\n<pre><code># Each file is much too large to fit into memory, so they are split into groups of 10,000 at \n# the O/S level.\n#\n# split -l 10000 -d -a 3 train_numeric.csv trn_num.csv\n#\n# results in 119 files names trn_num.csv###\n# Applying the same command to the other files so each set of identically numbered files will\n# fit in memory.\n# I'll apply xgboost to each file set, and save each tree independently.  Then, I'll run each \n# test row against each tree and average the results.\n\nlibrary(xgboost)\nxgforest &lt;- list()\nimportance_matrix &lt;- list()\nallcount &lt;- 0\ntruecount &lt;- 0\nfor (ti in 0:118) {\n    cat (&quot;Training chunk #&quot;,ti)\n    if (ti==0) {\n        hdr &lt;- TRUE\n    } else {\n        hdr &lt;- FALSE\n    }\n    a &lt;- read.csv(paste(&quot;trn_num.csv&quot;,sprintf(&quot;%03d&quot;,ti),sep=''),header=hdr)\n    allcount &lt;- allcount + nrow(a)\n    truecount &lt;- truecount + sum(a$Response)\n    \tb &lt;- read.csv(paste(&quot;trn_cat.csv&quot;,sprintf(&quot;%03d&quot;,ti),sep=''),header=hdr)\n    \tlof &lt;- lapply(b,is.factor)\n    \t#b &lt;- lapply(b,function(bc) if (is.factor(bc)) { as.numeric(bc) })\n    \tfor (bc in 2:ncol(b)) if (is.factor(b[,bc])) {b[,bc]&lt;-as.numeric(b[,bc])}\n    \tc &lt;- read.csv(paste(&quot;trn_date.csv&quot;,sprintf(&quot;%03d&quot;,ti),sep=''),header=hdr)\n    \tfor (cc in 2:ncol(c)) if (is.factor(c[,cc])) {c[,cc]&lt;-as.numeric(c[,cc])}\n    \tif (ti==0) {\n    \t\tanames &lt;- names(a)\n    \t\tbnames &lt;- names(b)\n    \t\tcnames &lt;- names(c)\n    \t} else {\n    \t\tnames(a) &lt;- anames\n    \t\tnames(b) &lt;- bnames\n    \t\tnames(c) &lt;- cnames\n    \t}\n    \td &lt;- cbind(a,b,all=TRUE)\n    \td &lt;- cbind(d,c,all=TRUE)\n    \td &lt;- d[,-970] # Response\n    \tresponse &lt;- a[,c(&quot;Id&quot;,&quot;Response&quot;)]\n    \trm(a)\n    \trm(b)\n    \trm(c)\n    \tdtrain &lt;- xgb.DMatrix(as.matrix(d[,-1]),label=response$Response,missing='')\n    xgmodel &lt;- xgboost(data=dtrain,objective=&quot;binary:logistic&quot;,eta=0.09,\n            nrounds=40,max_depth=25,verbose=1)\n    importance_matrix[[ti+1]] &lt;- xgb.importance(names(d[,-1]),model=xgmodel)\n    xgforest[[ti+1]] &lt;- xgmodel\n    rm(d)\n    rm(dtrain)\n}\nout &lt;- data.frame()\ncat(truecount,&quot; / &quot;,allcount,&quot;\\n&quot;)\nfor (si in 0:118) {\n    cat(&quot;Processing submission chunk&quot;,si,&quot;\\n&quot;)\n    if (si==0) {\n        hdr &lt;- TRUE\n    } else {\n        hdr &lt;- FALSE\n    }\n    a &lt;- read.csv(paste(&quot;tst_num.csv&quot;,sprintf(&quot;%03d&quot;,si),sep=''),header=hdr)\n    b &lt;- read.csv(paste(&quot;tst_cat.csv&quot;,sprintf(&quot;%03d&quot;,si),sep=''),header=hdr)\n    lof &lt;- lapply(b,is.factor)\n    #b &lt;- lapply(b,function(bc) if (is.factor(bc)) { as.numeric(bc) })\n    for (bc in 2:ncol(b)) if (is.factor(b[,bc])) {b[,bc]&lt;-as.numeric(b[,bc])}\n    c &lt;- read.csv(paste(&quot;tst_date.csv&quot;,sprintf(&quot;%03d&quot;,si),sep=''),header=hdr)\n    for (cc in 2:ncol(c)) if (is.factor(c[,cc])) {c[,cc]&lt;-as.numeric(c[,cc])}\n    if (si==0) {\n        anames &lt;- names(a)\n        bnames &lt;- names(b)\n        cnames &lt;- names(c)\n    } else {\n        names(a) &lt;- anames\n        names(b) &lt;- bnames\n        names(c) &lt;- cnames\n    }\n    d &lt;- cbind(a,b,all=TRUE)\n    d &lt;- cbind(d,c,all=TRUE)\n    rm(a)\n    rm(b)\n    rm(c)\n    submit_mtx &lt;- matrix(nrow=nrow(d),ncol=length(xgforest)+1)\n    dsubmit &lt;- xgb.DMatrix(as.matrix(d[,-1]),missing='')\n    mctr = 1\n    for (xgmodel in xgforest) {\n        submit_mtx[,mctr] &lt;- predict(xgmodel,dsubmit)\n        mctr &lt;- mctr + 1\n    }\n    meancol &lt;- length(xgforest)+1\n    for (r in 1:nrow(d)) submit_mtx[r,meancol] &lt;- round(max(submit_mtx[r,1:meancol-1]))\n    sub &lt;- cbind(d$Id,submit_mtx[,meancol])\n    \tout &lt;- rbind(out,sub)\n    }\n    names(out) &lt;- c(&quot;Id&quot;,&quot;Response&quot;)\n    out$Id &lt;- as.integer(out$Id)\n    write.csv(out,file=&quot;bosch_submit3.csv&quot;,row.names=FALSE,quote=FALSE)\n    cat (sum(out$Response))\nimp &lt;- as.character()\nfor (i in 1:length(importance_matrix)) imp &lt;- c(imp,importance_matrix[[i]]$Feature)\nimp_table &lt;- table(imp)\nimp_table &lt;- imp_table[order(imp_table,decreasing=TRUE)]\n</code></pre>",
      "rawMarkdown": "If you have Linux, GOW (GNU on Windows), or MSYS (part of MinGW), you can use the split command from a shell to break the training and test data into manageable chunks.  The syntax is\r\n\r\nsplit -l 10000 -d -a 3 train_numeric.csv trn_num.csv\r\n\r\nThen, in your R or Python script, use a for loop to cycle through the chunks, and then ensemble the models to get the best fit on the test data.  Here's my first submission:\r\n\r\n    # Each file is much too large to fit into memory, so they are split into groups of 10,000 at \r\n    # the O/S level.\r\n    #\r\n    # split -l 10000 -d -a 3 train_numeric.csv trn_num.csv\r\n    #\r\n    # results in 119 files names trn_num.csv###\r\n    # Applying the same command to the other files so each set of identically numbered files will\r\n    # fit in memory.\r\n    # I'll apply xgboost to each file set, and save each tree independently.  Then, I'll run each \r\n    # test row against each tree and average the results.\r\n    \r\n    library(xgboost)\r\n    xgforest <- list()\r\n    importance_matrix <- list()\r\n    allcount <- 0\r\n    truecount <- 0\r\n    for (ti in 0:118) {\r\n    \tcat (\"Training chunk #\",ti)\r\n    \tif (ti==0) {\r\n    \t\thdr <- TRUE\r\n    \t} else {\r\n    \t\thdr <- FALSE\r\n    \t}\r\n    \ta <- read.csv(paste(\"trn_num.csv\",sprintf(\"%03d\",ti),sep=''),header=hdr)\r\n    \tallcount <- allcount + nrow(a)\r\n    \ttruecount <- truecount + sum(a$Response)\r\n    \tb <- read.csv(paste(\"trn_cat.csv\",sprintf(\"%03d\",ti),sep=''),header=hdr)\r\n    \tlof <- lapply(b,is.factor)\r\n    \t#b <- lapply(b,function(bc) if (is.factor(bc)) { as.numeric(bc) })\r\n    \tfor (bc in 2:ncol(b)) if (is.factor(b[,bc])) {b[,bc]<-as.numeric(b[,bc])}\r\n    \tc <- read.csv(paste(\"trn_date.csv\",sprintf(\"%03d\",ti),sep=''),header=hdr)\r\n    \tfor (cc in 2:ncol(c)) if (is.factor(c[,cc])) {c[,cc]<-as.numeric(c[,cc])}\r\n    \tif (ti==0) {\r\n    \t\tanames <- names(a)\r\n    \t\tbnames <- names(b)\r\n    \t\tcnames <- names(c)\r\n    \t} else {\r\n    \t\tnames(a) <- anames\r\n    \t\tnames(b) <- bnames\r\n    \t\tnames(c) <- cnames\r\n    \t}\r\n    \td <- cbind(a,b,all=TRUE)\r\n    \td <- cbind(d,c,all=TRUE)\r\n    \td <- d[,-970] # Response\r\n    \tresponse <- a[,c(\"Id\",\"Response\")]\r\n    \trm(a)\r\n    \trm(b)\r\n    \trm(c)\r\n    \tdtrain <- xgb.DMatrix(as.matrix(d[,-1]),label=response$Response,missing='')\r\n    \txgmodel <- xgboost(data=dtrain,objective=\"binary:logistic\",eta=0.09,\r\n    \t\t\tnrounds=40,max_depth=25,verbose=1)\r\n    \timportance_matrix[[ti+1]] <- xgb.importance(names(d[,-1]),model=xgmodel)\r\n    \txgforest[[ti+1]] <- xgmodel\r\n    \trm(d)\r\n    \trm(dtrain)\r\n    }\r\n    out <- data.frame()\r\n    cat(truecount,\" / \",allcount,\"\\n\")\r\n    for (si in 0:118) {\r\n    \tcat(\"Processing submission chunk\",si,\"\\n\")\r\n    \tif (si==0) {\r\n    \t\thdr <- TRUE\r\n    \t} else {\r\n    \t\thdr <- FALSE\r\n    \t}\r\n    \ta <- read.csv(paste(\"tst_num.csv\",sprintf(\"%03d\",si),sep=''),header=hdr)\r\n    \tb <- read.csv(paste(\"tst_cat.csv\",sprintf(\"%03d\",si),sep=''),header=hdr)\r\n    \tlof <- lapply(b,is.factor)\r\n    \t#b <- lapply(b,function(bc) if (is.factor(bc)) { as.numeric(bc) })\r\n    \tfor (bc in 2:ncol(b)) if (is.factor(b[,bc])) {b[,bc]<-as.numeric(b[,bc])}\r\n    \tc <- read.csv(paste(\"tst_date.csv\",sprintf(\"%03d\",si),sep=''),header=hdr)\r\n    \tfor (cc in 2:ncol(c)) if (is.factor(c[,cc])) {c[,cc]<-as.numeric(c[,cc])}\r\n    \tif (si==0) {\r\n    \t\tanames <- names(a)\r\n    \t\tbnames <- names(b)\r\n    \t\tcnames <- names(c)\r\n    \t} else {\r\n    \t\tnames(a) <- anames\r\n    \t\tnames(b) <- bnames\r\n    \t\tnames(c) <- cnames\r\n    \t}\r\n    \td <- cbind(a,b,all=TRUE)\r\n    \td <- cbind(d,c,all=TRUE)\r\n    \trm(a)\r\n    \trm(b)\r\n    \trm(c)\r\n    \tsubmit_mtx <- matrix(nrow=nrow(d),ncol=length(xgforest)+1)\r\n    \tdsubmit <- xgb.DMatrix(as.matrix(d[,-1]),missing='')\r\n    \tmctr = 1\r\n    \tfor (xgmodel in xgforest) {\r\n    \t\tsubmit_mtx[,mctr] <- predict(xgmodel,dsubmit)\r\n    \t\tmctr <- mctr + 1\r\n    \t}\r\n    \tmeancol <- length(xgforest)+1\r\n    \tfor (r in 1:nrow(d)) submit_mtx[r,meancol] <- round(max(submit_mtx[r,1:meancol-1]))\r\n    \tsub <- cbind(d$Id,submit_mtx[,meancol])\r\n    \tout <- rbind(out,sub)\r\n    }\r\n    names(out) <- c(\"Id\",\"Response\")\r\n    out$Id <- as.integer(out$Id)\r\n    write.csv(out,file=\"bosch_submit3.csv\",row.names=FALSE,quote=FALSE)\r\n    cat (sum(out$Response))\r\n    imp <- as.character()\r\n    for (i in 1:length(importance_matrix)) imp <- c(imp,importance_matrix[[i]]$Feature)\r\n    imp_table <- table(imp)\r\n    imp_table <- imp_table[order(imp_table,decreasing=TRUE)]",
      "votes": null
    },
    {
      "id": "132627",
      "postDate": "08/27/2016 16:32:56",
      "content": "<p>As a note, I'm running this on a basic HP Envy laptop with 8GB RAM.</p>",
      "rawMarkdown": "As a note, I'm running this on a basic HP Envy laptop with 8GB RAM.",
      "votes": null
    },
    {
      "id": "132628",
      "postDate": "08/27/2016 17:03:59",
      "content": "<p>Nice script Michael !\nI am wondering what is the score of your first script?\nThanks</p>",
      "rawMarkdown": "Nice script Michael !\r\nI am wondering what is the score of your first script?\r\nThanks",
      "votes": null
    },
    {
      "id": "132639",
      "postDate": "08/27/2016 21:15:11",
      "content": "<p>It was in the 16s.</p>",
      "rawMarkdown": "It was in the 16s.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 132627,
      "author_name": "kb3gjt",
      "author_url": "",
      "post_date": "08/27/2016 16:32:56",
      "content": "<p>As a note, I'm running this on a basic HP Envy laptop with 8GB RAM.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 132628,
      "author_name": "alanwuxm",
      "author_url": "",
      "post_date": "08/27/2016 17:03:59",
      "content": "<p>Nice script Michael !\nI am wondering what is the score of your first script?\nThanks</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 132639,
      "author_name": "kb3gjt",
      "author_url": "",
      "post_date": "08/27/2016 21:15:11",
      "content": "<p>It was in the 16s.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "132626": "If you have Linux, GOW (GNU on Windows), or MSYS (part of MinGW), you can use the split command from a shell to break the training and test data into manageable chunks.  The syntax is\r\n\r\nsplit -l 10000 -d -a 3 train_numeric.csv trn_num.csv\r\n\r\nThen, in your R or Python script, use a for loop to cycle through the chunks, and then ensemble the models to get the best fit on the test data.  Here's my first submission:\r\n\r\n    # Each file is much too large to fit into memory, so they are split into groups of 10,000 at \r\n    # the O/S level.\r\n    #\r\n    # split -l 10000 -d -a 3 train_numeric.csv trn_num.csv\r\n    #\r\n    # results in 119 files names trn_num.csv###\r\n    # Applying the same command to the other files so each set of identically numbered files will\r\n    # fit in memory.\r\n    # I'll apply xgboost to each file set, and save each tree independently.  Then, I'll run each \r\n    # test row against each tree and average the results.\r\n    \r\n    library(xgboost)\r\n    xgforest <- list()\r\n    importance_matrix <- list()\r\n    allcount <- 0\r\n    truecount <- 0\r\n    for (ti in 0:118) {\r\n    \tcat (\"Training chunk #\",ti)\r\n    \tif (ti==0) {\r\n    \t\thdr <- TRUE\r\n    \t} else {\r\n    \t\thdr <- FALSE\r\n    \t}\r\n    \ta <- read.csv(paste(\"trn_num.csv\",sprintf(\"%03d\",ti),sep=''),header=hdr)\r\n    \tallcount <- allcount + nrow(a)\r\n    \ttruecount <- truecount + sum(a$Response)\r\n    \tb <- read.csv(paste(\"trn_cat.csv\",sprintf(\"%03d\",ti),sep=''),header=hdr)\r\n    \tlof <- lapply(b,is.factor)\r\n    \t#b <- lapply(b,function(bc) if (is.factor(bc)) { as.numeric(bc) })\r\n    \tfor (bc in 2:ncol(b)) if (is.factor(b[,bc])) {b[,bc]<-as.numeric(b[,bc])}\r\n    \tc <- read.csv(paste(\"trn_date.csv\",sprintf(\"%03d\",ti),sep=''),header=hdr)\r\n    \tfor (cc in 2:ncol(c)) if (is.factor(c[,cc])) {c[,cc]<-as.numeric(c[,cc])}\r\n    \tif (ti==0) {\r\n    \t\tanames <- names(a)\r\n    \t\tbnames <- names(b)\r\n    \t\tcnames <- names(c)\r\n    \t} else {\r\n    \t\tnames(a) <- anames\r\n    \t\tnames(b) <- bnames\r\n    \t\tnames(c) <- cnames\r\n    \t}\r\n    \td <- cbind(a,b,all=TRUE)\r\n    \td <- cbind(d,c,all=TRUE)\r\n    \td <- d[,-970] # Response\r\n    \tresponse <- a[,c(\"Id\",\"Response\")]\r\n    \trm(a)\r\n    \trm(b)\r\n    \trm(c)\r\n    \tdtrain <- xgb.DMatrix(as.matrix(d[,-1]),label=response$Response,missing='')\r\n    \txgmodel <- xgboost(data=dtrain,objective=\"binary:logistic\",eta=0.09,\r\n    \t\t\tnrounds=40,max_depth=25,verbose=1)\r\n    \timportance_matrix[[ti+1]] <- xgb.importance(names(d[,-1]),model=xgmodel)\r\n    \txgforest[[ti+1]] <- xgmodel\r\n    \trm(d)\r\n    \trm(dtrain)\r\n    }\r\n    out <- data.frame()\r\n    cat(truecount,\" / \",allcount,\"\\n\")\r\n    for (si in 0:118) {\r\n    \tcat(\"Processing submission chunk\",si,\"\\n\")\r\n    \tif (si==0) {\r\n    \t\thdr <- TRUE\r\n    \t} else {\r\n    \t\thdr <- FALSE\r\n    \t}\r\n    \ta <- read.csv(paste(\"tst_num.csv\",sprintf(\"%03d\",si),sep=''),header=hdr)\r\n    \tb <- read.csv(paste(\"tst_cat.csv\",sprintf(\"%03d\",si),sep=''),header=hdr)\r\n    \tlof <- lapply(b,is.factor)\r\n    \t#b <- lapply(b,function(bc) if (is.factor(bc)) { as.numeric(bc) })\r\n    \tfor (bc in 2:ncol(b)) if (is.factor(b[,bc])) {b[,bc]<-as.numeric(b[,bc])}\r\n    \tc <- read.csv(paste(\"tst_date.csv\",sprintf(\"%03d\",si),sep=''),header=hdr)\r\n    \tfor (cc in 2:ncol(c)) if (is.factor(c[,cc])) {c[,cc]<-as.numeric(c[,cc])}\r\n    \tif (si==0) {\r\n    \t\tanames <- names(a)\r\n    \t\tbnames <- names(b)\r\n    \t\tcnames <- names(c)\r\n    \t} else {\r\n    \t\tnames(a) <- anames\r\n    \t\tnames(b) <- bnames\r\n    \t\tnames(c) <- cnames\r\n    \t}\r\n    \td <- cbind(a,b,all=TRUE)\r\n    \td <- cbind(d,c,all=TRUE)\r\n    \trm(a)\r\n    \trm(b)\r\n    \trm(c)\r\n    \tsubmit_mtx <- matrix(nrow=nrow(d),ncol=length(xgforest)+1)\r\n    \tdsubmit <- xgb.DMatrix(as.matrix(d[,-1]),missing='')\r\n    \tmctr = 1\r\n    \tfor (xgmodel in xgforest) {\r\n    \t\tsubmit_mtx[,mctr] <- predict(xgmodel,dsubmit)\r\n    \t\tmctr <- mctr + 1\r\n    \t}\r\n    \tmeancol <- length(xgforest)+1\r\n    \tfor (r in 1:nrow(d)) submit_mtx[r,meancol] <- round(max(submit_mtx[r,1:meancol-1]))\r\n    \tsub <- cbind(d$Id,submit_mtx[,meancol])\r\n    \tout <- rbind(out,sub)\r\n    }\r\n    names(out) <- c(\"Id\",\"Response\")\r\n    out$Id <- as.integer(out$Id)\r\n    write.csv(out,file=\"bosch_submit3.csv\",row.names=FALSE,quote=FALSE)\r\n    cat (sum(out$Response))\r\n    imp <- as.character()\r\n    for (i in 1:length(importance_matrix)) imp <- c(imp,importance_matrix[[i]]$Feature)\r\n    imp_table <- table(imp)\r\n    imp_table <- imp_table[order(imp_table,decreasing=TRUE)]",
    "132627": "As a note, I'm running this on a basic HP Envy laptop with 8GB RAM.",
    "132628": "Nice script Michael !\r\nI am wondering what is the score of your first script?\r\nThanks",
    "132639": "It was in the 16s."
  },
  "source": "meta"
}