{
  "id": 10841,
  "title": "Workflow and Infrastructure",
  "url": "/competitions/avazu-ctr-prediction/discussion/10841",
  "author_name": "",
  "post_date": "2014-11-05T05:00:06.853Z",
  "votes": 3,
  "comment_count": 9,
  "views": 2760,
  "content": "<p>I am new to Kaggle and would like to get some advice.</p>\n<p>Can you guys share your workflow and infrastructure?<br>Generally, how do you deal with datasets that do not fit into memory?</p>\n<p>I am using R and would like to know how to make use of packages like bigmemory and ff along with various machine learning algorithm packages.</p>\n<p>Thanks.</p>",
  "messages": [
    {
      "id": "57338",
      "postDate": "11/05/2014 05:00:06",
      "content": "<p>I am new to Kaggle and would like to get some advice.</p>\n<p>Can you guys share your workflow and infrastructure?<br>Generally, how do you deal with datasets that do not fit into memory?</p>\n<p>I am using R and would like to know how to make use of packages like bigmemory and ff along with various machine learning algorithm packages.</p>\n<p>Thanks.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57359",
      "postDate": "11/05/2014 19:23:21",
      "content": "<p>I'm in the same boat. I come from CS and bioinformatics so some guidance/ advice would be great =)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57364",
      "postDate": "11/05/2014 21:52:11",
      "content": "<p>Vowpal Wabbit is a popular tool for datasets that don't fit into memory; you can also always average models built on subsets of the data if you don't want to learn a new tool. &nbsp;I suspect many competitors rent out computing power/extra memory from Amazon EC2, although many libraries have an effective size limit that is smaller than your actual available RAM.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57383",
      "postDate": "11/06/2014 05:45:55",
      "content": "<p>R is great, but it's said that because of inefficiency of R's underlying memory model, it sucks when the size of data exceeds 2 gigabytes.</p>\n<p>Nevertheless, having the whole dataset available is great, but no one says that you can't perform your analysis with a carefully selected sample of your data. After all most users of R are statisticians and they are good at testing their hypothesis with sufficient - not necessarily all - data.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57443",
      "postDate": "11/06/2014 22:44:46",
      "content": "<p>You can train using <a href=\"http://en.wikipedia.org/wiki/Online_machine_learning\" target=\"_blank\">online learning techniques</a>&nbsp;which means you perform your calculation one item at a time. You can also use the <a href=\"http://en.wikipedia.org/wiki/MapReduce\" target=\"_blank\">MapReduce </a>approach which I think is used by <a href=\"http://0xdata.com/h2o/\" target=\"_blank\">H2O</a>. Engineering good features is a key to success and <a href=\"http://en.wikipedia.org/wiki/Dimensionality_reduction\" target=\"_blank\">dimensionality reduction</a>&nbsp;like <a href=\"http://en.wikipedia.org/wiki/Principal_component_analysis\" target=\"_blank\">PCA&nbsp;</a>often comes to help. &nbsp;Some people also&nbsp;use graphic card to speed up their algorithms with&nbsp;<a href=\"http://www.nvidia.com/object/machine-learning.html\" target=\"_blank\">CUDA</a>.<br><br><br></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57445",
      "postDate": "11/07/2014 00:38:23",
      "content": "<p>I am using R. Still working on this but the plan is to read the training data in 5,000,000 rows at a time and save as .Rda files. Then, I can fit a logistic regression model using biglm. I can use the update function in biglm to fit the model one dataset at a time.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57496",
      "postDate": "11/08/2014 01:04:52",
      "content": "<p>[quote=AlKhwarizmi;57445]</p>\n<p>I am using R. Still working on this but the plan is to read the training data in 5,000,000 rows at a time and save as .Rda files. Then, I can fit a logistic regression model using biglm. I can use the update function in biglm to fit the model one dataset at a time.</p>\n<p>[/quote]</p>\n<p>I am still working on this. I have 70% of the training data read and saved. I thought this would be simple to do with read.csv() using skip and nrows but each segment takes longer and uses more memory than the last. Is it possible that &quot;skip = 35000001&quot; doesn't actually skip 35000001 rows? Is there something else I am doing wrong? See R code:</p>\n<p>dtypes = c(&quot;character&quot;,&quot;numeric&quot;,&quot;numeric&quot;,&quot;character&quot;,&quot;character&quot;,<br> &quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,<br> &quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,<br> &quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;numeric&quot;,<br> &quot;numeric&quot;,&quot;numeric&quot;,&quot;numeric&quot;,&quot;numeric&quot;,&quot;numeric&quot;,<br> &quot;numeric&quot;,&quot;numeric&quot;)</p>\n<p>train8 = read.csv(&quot;data/train_rev2.csv&quot;,header=FALSE,nrows=5000000,<br> colClasses=dtypes,skip=35000001)<br><br></p>\n<p>This ran for about 18 hours and my memory (8GB) was at 99%. I killed it because the 7th dataset only took about 30 minutes.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57502",
      "postDate": "11/08/2014 07:02:25",
      "content": "<p>If you want to go with R, I suggest that you use data.table package. It is especially optimized for very large table manipulation.</p>\n<p>Have a look at the fread function, which can read large tables very efficiently - more than x4 faster than read.csv on my PC, and I can then read 5M records in 28 sec with:</p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp; system.time({ raw = fread(file, nrows = 5000000) })</p>\n<p>Reading the whole table is also feasible, but I then use up 8GB of RAM. Manipulations such as counting and so on are quite easy. For instance, you can get the percentage of positive clicks and number of events per device_os very quickly with the following command:</p>\n<p>&nbsp;&nbsp;&nbsp; raw[,list(m = mean(click), c = length(click)), by=device_os]</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "57525",
      "postDate": "11/08/2014 17:37:29",
      "content": "<p>Thanks, I will try that. I also tried reading the files with Pandas in Python. Same result. Unfortunately, my notebook has only 8GB memory.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "59250",
      "postDate": "11/30/2014 01:26:49",
      "content": "<p>Here is an another approach,&nbsp;Check it out. It might help.</p>\n<p>http://www.r-bloggers.com/big-data-logistic-regression-with-r-and-odbc/</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 57359,
      "author_name": "frederickvanstaden",
      "author_url": "",
      "post_date": "11/05/2014 19:23:21",
      "content": "<p>I'm in the same boat. I come from CS and bioinformatics so some guidance/ advice would be great =)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57364,
      "author_name": "telser",
      "author_url": "",
      "post_date": "11/05/2014 21:52:11",
      "content": "<p>Vowpal Wabbit is a popular tool for datasets that don't fit into memory; you can also always average models built on subsets of the data if you don't want to learn a new tool. &nbsp;I suspect many competitors rent out computing power/extra memory from Amazon EC2, although many libraries have an effective size limit that is smaller than your actual available RAM.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57383,
      "author_name": "",
      "author_url": "",
      "post_date": "11/06/2014 05:45:55",
      "content": "<p>R is great, but it's said that because of inefficiency of R's underlying memory model, it sucks when the size of data exceeds 2 gigabytes.</p>\n<p>Nevertheless, having the whole dataset available is great, but no one says that you can't perform your analysis with a carefully selected sample of your data. After all most users of R are statisticians and they are good at testing their hypothesis with sufficient - not necessarily all - data.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57443,
      "author_name": "alexandrekowalczyk",
      "author_url": "",
      "post_date": "11/06/2014 22:44:46",
      "content": "<p>You can train using <a href=\"http://en.wikipedia.org/wiki/Online_machine_learning\" target=\"_blank\">online learning techniques</a>&nbsp;which means you perform your calculation one item at a time. You can also use the <a href=\"http://en.wikipedia.org/wiki/MapReduce\" target=\"_blank\">MapReduce </a>approach which I think is used by <a href=\"http://0xdata.com/h2o/\" target=\"_blank\">H2O</a>. Engineering good features is a key to success and <a href=\"http://en.wikipedia.org/wiki/Dimensionality_reduction\" target=\"_blank\">dimensionality reduction</a>&nbsp;like <a href=\"http://en.wikipedia.org/wiki/Principal_component_analysis\" target=\"_blank\">PCA&nbsp;</a>often comes to help. &nbsp;Some people also&nbsp;use graphic card to speed up their algorithms with&nbsp;<a href=\"http://www.nvidia.com/object/machine-learning.html\" target=\"_blank\">CUDA</a>.<br><br><br></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57445,
      "author_name": "alkhwarizmi",
      "author_url": "",
      "post_date": "11/07/2014 00:38:23",
      "content": "<p>I am using R. Still working on this but the plan is to read the training data in 5,000,000 rows at a time and save as .Rda files. Then, I can fit a logistic regression model using biglm. I can use the update function in biglm to fit the model one dataset at a time.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57496,
      "author_name": "alkhwarizmi",
      "author_url": "",
      "post_date": "11/08/2014 01:04:52",
      "content": "<p>[quote=AlKhwarizmi;57445]</p>\n<p>I am using R. Still working on this but the plan is to read the training data in 5,000,000 rows at a time and save as .Rda files. Then, I can fit a logistic regression model using biglm. I can use the update function in biglm to fit the model one dataset at a time.</p>\n<p>[/quote]</p>\n<p>I am still working on this. I have 70% of the training data read and saved. I thought this would be simple to do with read.csv() using skip and nrows but each segment takes longer and uses more memory than the last. Is it possible that &quot;skip = 35000001&quot; doesn't actually skip 35000001 rows? Is there something else I am doing wrong? See R code:</p>\n<p>dtypes = c(&quot;character&quot;,&quot;numeric&quot;,&quot;numeric&quot;,&quot;character&quot;,&quot;character&quot;,<br> &quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,<br> &quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,<br> &quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;character&quot;,&quot;numeric&quot;,<br> &quot;numeric&quot;,&quot;numeric&quot;,&quot;numeric&quot;,&quot;numeric&quot;,&quot;numeric&quot;,<br> &quot;numeric&quot;,&quot;numeric&quot;)</p>\n<p>train8 = read.csv(&quot;data/train_rev2.csv&quot;,header=FALSE,nrows=5000000,<br> colClasses=dtypes,skip=35000001)<br><br></p>\n<p>This ran for about 18 hours and my memory (8GB) was at 99%. I killed it because the 7th dataset only took about 30 minutes.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57502,
      "author_name": "martely",
      "author_url": "",
      "post_date": "11/08/2014 07:02:25",
      "content": "<p>If you want to go with R, I suggest that you use data.table package. It is especially optimized for very large table manipulation.</p>\n<p>Have a look at the fread function, which can read large tables very efficiently - more than x4 faster than read.csv on my PC, and I can then read 5M records in 28 sec with:</p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp; system.time({ raw = fread(file, nrows = 5000000) })</p>\n<p>Reading the whole table is also feasible, but I then use up 8GB of RAM. Manipulations such as counting and so on are quite easy. For instance, you can get the percentage of positive clicks and number of events per device_os very quickly with the following command:</p>\n<p>&nbsp;&nbsp;&nbsp; raw[,list(m = mean(click), c = length(click)), by=device_os]</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 57525,
      "author_name": "alkhwarizmi",
      "author_url": "",
      "post_date": "11/08/2014 17:37:29",
      "content": "<p>Thanks, I will try that. I also tried reading the files with Pandas in Python. Same result. Unfortunately, my notebook has only 8GB memory.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 59250,
      "author_name": "bgopalakrishnan",
      "author_url": "",
      "post_date": "11/30/2014 01:26:49",
      "content": "<p>Here is an another approach,&nbsp;Check it out. It might help.</p>\n<p>http://www.r-bloggers.com/big-data-logistic-regression-with-r-and-odbc/</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "57338": "",
    "57359": "",
    "57364": "",
    "57383": "",
    "57443": "",
    "57445": "",
    "57496": "",
    "57502": "",
    "57525": "",
    "59250": ""
  },
  "source": "meta"
}