{
  "id": 7666,
  "title": "Getting started - data reduction",
  "url": "/competitions/acquire-valued-shoppers-challenge/discussion/7666",
  "author_name": "",
  "post_date": "2014-04-11T15:48:05.003Z",
  "votes": 33,
  "comment_count": 42,
  "views": 32354,
  "content": "<p>Just for getting started, to get the data down to a more manageable size, I extracted only transactions where the category was a category on at least one of the offers. This got the transactions down from about 22GB to about 1GB.</p>\n<p>Obviously, as the competition progresses, I'd recommend delving into the &quot;other 21GB&quot; but this might help getting started.</p>\n<p>Code is below. It is a combo of grep and R.</p>\n<p>-----------------</p>\n<p>Unix script for getting transactions where category is in at least one offer. WARNING, this will pick up some junk rows and maybe&nbsp;even duplicate rows because of grep matching other parts of the row.</p>\n<p>grep &quot;,706,&quot; transactions &gt; trans_cat.csv<br>grep &quot;,799,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,1703,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,1726,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,2119,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,2202,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,3203,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,3504,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,3509,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,4401,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,4517,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5122,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5558,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5616,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5619,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5824,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,6202,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,7205,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,9115,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,9909,&quot; transactions &gt;&gt; trans_cat.csv</p>\n<p><br># R code to weed out junk rows that were accidentally picked up by grep.</p>\n<p># If duplicates exist, getting rid of them is left as an exercise to the reader.</p>\n<p>trans_cat &lt;- read.csv(&quot;trans_cat.csv&quot;,header=TRUE)<br>nrow(trans_cat)<br>table(trans_cat$category)</p>\n<p>trans_cat &lt;- trans_cat[which(trans_cat$category %in% c(706,799,1703,1726,2119,2202,3203,3504,3509,4401,4517,5122,5558,5616,5619,5824,6202,7205,9115,9909)),]<br>nrow(trans_cat)<br>table(trans_cat$category)</p>",
  "messages": [
    {
      "id": "41729",
      "postDate": "04/11/2014 15:48:05",
      "content": "<p>Just for getting started, to get the data down to a more manageable size, I extracted only transactions where the category was a category on at least one of the offers. This got the transactions down from about 22GB to about 1GB.</p>\n<p>Obviously, as the competition progresses, I'd recommend delving into the &quot;other 21GB&quot; but this might help getting started.</p>\n<p>Code is below. It is a combo of grep and R.</p>\n<p>-----------------</p>\n<p>Unix script for getting transactions where category is in at least one offer. WARNING, this will pick up some junk rows and maybe&nbsp;even duplicate rows because of grep matching other parts of the row.</p>\n<p>grep &quot;,706,&quot; transactions &gt; trans_cat.csv<br>grep &quot;,799,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,1703,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,1726,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,2119,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,2202,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,3203,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,3504,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,3509,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,4401,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,4517,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5122,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5558,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5616,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5619,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,5824,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,6202,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,7205,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,9115,&quot; transactions &gt;&gt; trans_cat.csv<br>grep &quot;,9909,&quot; transactions &gt;&gt; trans_cat.csv</p>\n<p><br># R code to weed out junk rows that were accidentally picked up by grep.</p>\n<p># If duplicates exist, getting rid of them is left as an exercise to the reader.</p>\n<p>trans_cat &lt;- read.csv(&quot;trans_cat.csv&quot;,header=TRUE)<br>nrow(trans_cat)<br>table(trans_cat$category)</p>\n<p>trans_cat &lt;- trans_cat[which(trans_cat$category %in% c(706,799,1703,1726,2119,2202,3203,3504,3509,4401,4517,5122,5558,5616,5619,5824,6202,7205,9115,9909)),]<br>nrow(trans_cat)<br>table(trans_cat$category)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41735",
      "postDate": "04/11/2014 16:10:42",
      "content": "<p>Use,&nbsp;awk -F, '$4 = 706' transactions &gt; trans_cat.csv &nbsp;and so on to avoid junk rows</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41752",
      "postDate": "04/11/2014 20:03:51",
      "content": "<p>My machine can't read more than about 50 MB, at once. Just curious what kind of rigs professionals have in place? Do you guys use clusters/hadoop?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41758",
      "postDate": "04/11/2014 22:10:53",
      "content": "<p>You can do most challenges on Kaggle on a budget laptop. SSD helps. 16GB memory helps. Some professionals which I envy have access to clusters and servers, but that is not needed to win a contest. If nothing else, you learn how to be more resourceful (using less resources) and care more about speed.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41764",
      "postDate": "04/11/2014 22:34:09",
      "content": "<p>I agree with Triskelion. &nbsp;I am able to use my 8GB laptop for most Kaggle contests. If there is a contest that requires a large amount of memory, I sometimes rent an Amazon EC2 instance with 32GB for a couple weeks.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41774",
      "postDate": "04/12/2014 02:29:31",
      "content": "<p>I've also found that another useful subset is: only transactions where the company was a company on at least one of the offers. &nbsp;This was also about 1GB. &nbsp;There is obviously some overlap between this and the category subset. &nbsp;What would be best would be to have the union of these without duplicates.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41820",
      "postDate": "04/12/2014 22:56:44",
      "content": "<p>In Python to reduce from 20GB to about 1GB (349.655.789 lines to 15.349.956 lines) or &quot;the category subset&quot; as BreakfastPirate calls it:</p>\n<p><code>from datetime import datetime</code></p>\n<p><code></code><code>loc_offers = &quot;kaggle_shop\\\\offers.csv&quot;<br>loc_transactions = &quot;kaggle_shop\\\\transactions.csv&quot;<br>loc_reduced = &quot;kaggle_shop\\\\reduced2.csv&quot; # will be created</code></p>\n<p><code><code>def&nbsp;</code>reduce_data(loc_offers, loc_transactions, loc_reduced):</code></p>\n<p><code>&nbsp; start = datetime.now()<br>&nbsp; #get all categories on offer in a dict<br>&nbsp; offers = {}<br>&nbsp; for e, line in enumerate( open(loc_offers) ):<br>&nbsp; &nbsp; offers[ line.split(&quot;,&quot;)[1] ] = 1<br>&nbsp; #open output file<br>&nbsp; with open(loc_reduced, &quot;wb&quot;) as outfile:<br>&nbsp; &nbsp; #go through transactions file and reduce<br>&nbsp; &nbsp; reduced = 0<br>&nbsp; &nbsp; for e, line in enumerate( open(loc_transactions) ):<br>&nbsp; &nbsp; &nbsp; if e == 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; outfile.write( line ) #print header<br>&nbsp; &nbsp; &nbsp; else:<br>&nbsp; &nbsp; &nbsp; &nbsp; #only write when category in offers dict<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if line.split(&quot;,&quot;)[3] in offers:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outfile.write( line )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reduced += 1<br>&nbsp; &nbsp; &nbsp; #progress<br>&nbsp; &nbsp; &nbsp; if e % 5000000 == 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; print e, reduced, datetime.now() - start<br>&nbsp; print e, reduced, datetime.now() - start</code></p>\n<p><code>reduce_data(loc_offers, loc_transactions, loc_reduced)</code></p>\n<p>if you want to reduce the data with company, change:</p>\n<p><code>offers[ line.split(&quot;,&quot;)[1] ] = 1&nbsp;<br></code></p>\n<p>to:</p>\n<p><code>offers[ line.split(&quot;,&quot;)[3] ] = 1</code></p>\n<p>and:</p>\n<p><code>if line.split(&quot;,&quot;)[3] in offers</code></p>\n<p>to:</p>\n<p><code>if line.split(&quot;,&quot;)[4] in offers</code></p>\n<p>The category+company union is about 27 million lines (1.6Gb).</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41821",
      "postDate": "04/12/2014 23:11:24",
      "content": "<p>Python is good for these kind of tasks - the standard CPython is pretty slow, but if your script uses only standard libraries and doesn't use numpy, sklearn, etc. then you should be able to run it with pypy, which is really fast, can be easily an order of magnitude faster than CPython. I think Triskelion's script would take about 10 minutes to process the transactions data on an average PC (I've written something similar to reduce the amount of data).</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41822",
      "postDate": "04/12/2014 23:20:24",
      "content": "<p>Yup, about 10 minutes to write, about 10 minutes to run. Not the fastest, but should work on any PC (takes max 6mb memory).</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41842",
      "postDate": "04/13/2014 11:32:55",
      "content": "<p>It takes exactly 3:29 with both PyPy and CPython to run that filtering script on my laptop.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "41850",
      "postDate": "04/13/2014 16:44:47",
      "content": "<p>Transaction file summary statistics:</p>\n\n<p>349655789 records</p>\n<p>total purchasequantity&nbsp;584540514</p>\n<p>total purchaseamount&nbsp;1568488398</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "42660",
      "postDate": "04/22/2014 01:09:09",
      "content": "<p>My recommendation - Download Datameer and get 15 days trial edition.</p>\n<p>Create one workbook in datameer that merges the offers + trainhistory&nbsp;+ transactions.</p>\n<p>You are ready to go</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43083",
      "postDate": "04/26/2014 16:03:13",
      "content": "<p>hi! and how did you do that?</p>\n<p>which variables did you use to merge the 3 tables??? the relation is 1to1??</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43097",
      "postDate": "04/26/2014 19:04:49",
      "content": "<p>[quote=neeraj;42660]</p>\n<p>My recommendation - Download Datameer and get 15 days trial edition.</p>\n<p>Create one workbook in datameer that merges the offers + trainhistory + transactions.</p>\n<p>You are ready to go</p>\n<p>[/quote]</p>\n<p>Why pay for commercial software when R and python are free?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43098",
      "postDate": "04/26/2014 19:21:12",
      "content": "<p>Data sets of this size, might be larger than the memory of the computer could hold. Open source R will may fail&nbsp;in such scenarios. (Unless you use packages like ff/bigmemory/bigglm). Revolution R Enterprise, uses external memory algorithms have no data limits, and is easier to use than ff/bigmemory/bigglm.</p>\n<p>It is available for Kaggle users for free for participating in Kaggle contests. Download here</p>\n<p>http://info.revolutionanalytics.com/Kaggle.html</p>\n<p>[post edited to incorporate comments from Zach]</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43103",
      "postDate": "04/26/2014 20:18:18",
      "content": "<p>[quote=James Paul;43098]</p>\n<p>Data sets of this size, might be larger than the memory of the computer could hold. Open source R will fail in such scenarios. Revolution R Enteprise, uses external memory algorithms have no data limits.</p>\n<p>It is available for Kaggle users for free for participating in Kaggle contests. Download here</p>\n<p>http://info.revolutionanalytics.com/Kaggle.html</p>\n<p>[/quote]</p>\n<p>The dataset for this competition will fit in memory on a computer with 16 gigs of RAM. &nbsp;Furthermore, open source R can use out-of-memory algorithms, for example with the <a href=\"http://www.bigmemory.org/\">bigmemory</a>&nbsp;and <a href=\"http://cran.r-project.org/web/packages/ff/index.html\">ff</a>&nbsp;packages.</p>\n<p>Don't get me wrong, I love Revolution R: I have the t-shirt and foreach is one of my favorite packages. &nbsp;But open-source R is definitely up for this challenge.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43416",
      "postDate": "05/01/2014 01:20:18",
      "content": "<p>Thank you for referring to revolutionanalytics (RA). I downloaded their software and attempted to import the entire transactions file. But ran out of memory as the import was being handled locally. I have a windows xp 4GB RAM laptop. Does anyone know if we can leverage RA's remote computing capability for kaggle comps? and if so, will appreciate any info on how to do this. On the side I am also giving the ff package a go as well but again limited by memory issues. And I am also aware of other opportunities to scale down data size from previous forum contributions.&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43417",
      "postDate": "05/01/2014 01:40:26",
      "content": "<p>Please contact support@revolutionanalytics.com with your specific error. I have a 16GB laptop and I imported the data easily. I used the following commands to import to the Extended Data Frame format.</p>\n<p>offers&lt;-rxImport(inData=&quot;offers.csv&quot;, outFile=&quot;offers.xdf&quot;, stringsAsFactors=TRUE, missingValueString=&quot;M&quot;)<br>trainHistory&lt;-rxImport(inData=&quot;trainHistory.csv&quot;, outFile=&quot;trainHistory.xdf&quot;, stringsAsFactors=TRUE, missingValueString=&quot;M&quot;)<br>tx&lt;-rxImport(inData=&quot;transactions.csv&quot;, outFile=&quot;tx.xdf&quot;, stringsAsFactors=TRUE, missingValueString=&quot;M&quot;) (It does take time to import this one)</p>\n<p>You can merge/combine the .xdf files to proceed with the next steps. (Use rxDataStep command)</p>\n<p>The user guide has a number of commonly used scenarios in manipulating data.</p>\n<p>You can also use Revolution R Enterprise in AWS. (You can get upto 64GB RAM machines)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43489",
      "postDate": "05/02/2014 01:57:55",
      "content": "<p>&quot;fread&quot; from the data.table package is also sufficient to load the full dataset in open source R (at least on a mac).</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43522",
      "postDate": "05/02/2014 18:21:10",
      "content": "<p>I have a windows xp laptop 2GB RAM, and I get good results in Kaggle competitions ... even a winning price ... I use speed (Kaggle user license) and python ...</p>\n<p>I think this enough for this competition, but needs a careful treatment of data ...</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43626",
      "postDate": "05/03/2014 19:34:08",
      "content": "<p>@Triskelion</p>\n<p>Great reduction code sir!</p>\n<p>I ran it in a little over 6 minutes and reduced down to 1GB. &nbsp;I was wondering if you can you provide an explanation, line by line what is going on for the group? I am new to python but I understand some of the basics.&nbsp;</p>\n<p>Basically, I wanted to know why this works and something like just usingn pandas and dataframes crashes. &nbsp;Is it because you're only doing a pivot table and filtering on 5million records at a time?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "43646",
      "postDate": "05/03/2014 23:32:04",
      "content": "<p>[quote=Neil Patel;43626]</p>\n<p>@Triskelion</p>\n<p>Great reduction code sir!</p>\n<p>I ran it in a little over 6 minutes and reduced down to 1GB. &nbsp;I was wondering if you can you provide an explanation, line by line what is going on for the group? I am new to python but I understand some of the basics.&nbsp;</p>\n<p>Basically, I wanted to know why this works and something like just usingn pandas and dataframes crashes. &nbsp;Is it because you're only doing a pivot table and filtering on 5million records at a time?</p>\n<p>[/quote]</p>\n<p>Ty sir. I will provide an explanation, line by line, but do keep in mind that I am new to Python too, you may just be a tad newer.&nbsp;</p>\n<p>Why this works and not using pandas, I think is because you try to create a dataframe of the entire dataset (before reducing). With ~8GB mem you probably want to read the data line by line or in chunks. It is possible that Pandas is faster than my code if you make smart use of '<a href=\"http://pandas.pydata.org/pandas-docs/stable/io.html#io-chunking\">chunksize</a>' and possibly an iterator.</p>\n<p>BTW: Are you Neil Patel from&nbsp;Seattle? If so, I am a big fan, sir!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44373",
      "postDate": "05/11/2014 13:37:20",
      "content": "<p>Thanks</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44563",
      "postDate": "05/14/2014 23:37:18",
      "content": "<p>Triskelion awesome starter code. &nbsp;Interestingly I was implementing my own version of this code but noticed it was running substantially slower than original. &nbsp;Turns out, I was defining the &quot;offer&quot; as an array rather than a dictionary which made a huge difference in the speed of the code. &nbsp;I am relatively new to python and was wondering if anyone could comment as to why this occurs.</p>\n\n<p>offer = [] #runs slow</p>\n<p>offer = {} # runs quickly</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44567",
      "postDate": "05/15/2014 01:55:50",
      "content": "<p>How do you figure out that the performance issue of your program is due to list? (Did you use a profiler or ...)</p>\n<p>Since offer.csv is not large, I doubt whether using list to store the offers will slow down the program substantially</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44575",
      "postDate": "05/15/2014 04:11:33",
      "content": "<p>There is a time stamp within the code. &nbsp;It also reports the row which it is on. &nbsp;It clearly was taking longer to run the script based on observation. &nbsp;You are correct, offer.csv is small; however transactions.csv is very large. &nbsp;I believe the issue to be how the created dictionary from offer.csv&nbsp;is used to cross reference against the data in the transaction file when the for loop to check to see if some value from offer is found within the transactions file.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44577",
      "postDate": "05/15/2014 06:35:57",
      "content": "<p>Hmm, maybe you are right.</p>\n<p>But why not just using dict? Don't waste your time on list and dict, after all, it's not the major part of the competition</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44619",
      "postDate": "05/15/2014 15:54:19",
      "content": "<p>I ended up using a dict for the code, but it took me a little while to figure out that was the issue. &nbsp;I am mostly wondering why the code performs differently since the data within the dict or list is the same size. &nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44621",
      "postDate": "05/15/2014 16:04:00",
      "content": "<p>You need to provide more information (i.e. link to your code) if you want an answer.</p>\n<p>You can not generally replace a list with a dict (and vice versa), since their construction will differ. You might be using:</p>\n<p>&nbsp; &nbsp; if <em>something</em> in offers:</p>\n<p>This will be O(1) for dict, and O(n) for list. That is, to answer if some key is in a dictionary takes 1 unit of time, and to answer if some key is in a list takes some amount of time proportional to the amount of elements in the list.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44677",
      "postDate": "05/16/2014 18:42:04",
      "content": "<p>[quote=Nolan Wilson;44563]</p>\n<p>I am relatively new to python and was wondering if anyone could comment as to why this occurs.</p>\n<p>offer = [] #runs slow</p>\n<p>offer = {} # runs quickly</p>\n<p>[/quote]</p>\n<p>&quot;If key in dictionary&quot;</p>\n<p>is faster than:</p>\n<p>&quot;If key in list&quot;.</p>\n<p>From https://wiki.python.org/moin/PythonSpeed:</p>\n<p><em>Membership testing with sets and dictionaries is much faster, O(1), than searching sequences, O(n). When testing &quot;a in b&quot;, b should be a set or dictionary instead of a list or tuple.</em></p>\n<p>Why this is? I think this is (not an expert) because Python dictionaries are <a href=\"http://en.wikipedia.org/wiki/Hash_table\">hash tables</a>&nbsp;or hash mappings. Notes on the original implementation <a href=\"https://mail.python.org/pipermail/python-list/2000-March/048085.html\">here</a>. Like the above quote on Python speed best practices, checking if an item is a member of a hash table is near instant, in the case of a list, it has to check every member if it is the same, and so has to traverse the entire list in the worst case scenario (when the item is not in the list).</p>\n<p>Source for DictObject &quot;with comments&quot; at:&nbsp;http://svn.python.org/view/python/trunk/Objects/dictobject.c?view=markup</p>\n<p>Since the membership check occurs in the loop that scans every transaction record, it is run ~350million times. That extra&nbsp;0.00001 second it takes for a check&nbsp;may then turn into an hour.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44678",
      "postDate": "05/16/2014 18:48:27",
      "content": "<p>dict is always faster than the list in python (comparable for small data)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44771",
      "postDate": "05/18/2014 07:22:25",
      "content": "<p>Hello, do you know if it is possible to reduce the file size only using R? I don't have Unix. :(</p>\n<p>I tried to read the R transactions file, however it failed as the file is too big to read. :(</p>\n\n<p>Thanks</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "44793",
      "postDate": "05/18/2014 19:47:20",
      "content": "<p>There are Unix commands available for Windows. &nbsp;Here is one source:&nbsp;http://unxutils.sourceforge.net/</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "45982",
      "postDate": "05/21/2014 10:33:07",
      "content": "<p>[quote=Nubee;44771]</p>\n<p>Hello, do you know if it is possible to reduce the file size only using R? I don't have Unix. :(</p>\n<p>I tried to read the R transactions file, however it failed as the file is too big to read. :(</p>\n<p>Thanks</p>\n<p>[/quote]</p>\n<p>Option 1, split the file and process them in R and merge the results</p>\n<p>Option 2, use read.table with skip and nrows multiple times and merger the results.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49266",
      "postDate": "06/18/2014 03:20:48",
      "content": "<p>I think the R code below does the same thing as the data reduction being discussed in this thread, i.e. create a subset of transactions containing only the category corresponding to the offer which was received. But the result has 987,246 rows, considerably less than the 15.349.956 that Triskelion got with his Python code.&nbsp; As far as I know this code does not pick up categories corresponding to offers received by other customers. Perhaps the Python code does? Either that or this code is not working like I think it should. This is my first time using the data.table package.</p>\n\n<p style=\"padding-left: 30px\">library(data.table)</p>\n<p style=\"padding-left: 30px\">transactions &lt;- fread(&quot;transactions.csv&quot;,integer64=&quot;character&quot;)<br>offers &lt;- fread(&quot;offers.csv&quot;,integer64=&quot;character&quot;)<br>train &lt;- fread(&quot;trainHistory.csv&quot;,integer64=&quot;character&quot;)</p>\n<p style=\"padding-left: 30px\">setkey(offers,offer,category)<br>setkey(train,offer)<br>train &lt;- merge(train,offers,all.x=TRUE)</p>\n<p style=\"padding-left: 30px\">setkey(transactions,id,category)<br>setkey(train,id,category)<br>train.transcat &lt;- transactions[train]<br>dim(train.transcat); head(train.transcat)<br>#[1] 987246 21</p>\n<p style=\"padding-left: 30px\">&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49345",
      "postDate": "06/20/2014 18:37:17",
      "content": "<p>I have a laptop with 4 gigs of RAM and I am trying to read the transaction.csv file using the read.csv.ffdf command.... &quot;read.csv.ffdf(file=&quot;transactions.csv&quot;, header=TRUE, VERBOSE=TRUE, nrows=20000, next.rows=500000, colClasses=NA)&quot;....&nbsp; I can read rows starting from 1 itself to whatever no. I wish which is not a problem&nbsp;but I am not able to set specific no. of rows &nbsp;as arguments in this command... like I want to read no. of rows starting from 10000 to 20000... please suggest some other command where I can set the no. of row to start with... Also I dont I have an access to UNIX...!&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50211",
      "postDate": "07/09/2014 16:00:58",
      "content": "<p>you can also rent an EC2 HANA system (in-memory database from SAP), load the data and do everything via SQL.</p>\n<p>Queries on the 300Mio rows run in sub-second response times... :-)</p>\n\n<p>br, WM</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50258",
      "postDate": "07/10/2014 09:41:17",
      "content": "<p>[quote=Sarah Hardy;49266]</p>\n<p>I think the R code below does the same thing as the data reduction being discussed in this thread, i.e. create a subset of transactions containing only the category corresponding to the offer which was received. But the result has 987,246 rows, considerably less than the 15.349.956 that Triskelion got with his Python code.&nbsp; As far as I know this code does not pick up categories corresponding to offers received by other customers. Perhaps the Python code does? Either that or this code is not working like I think it should. This is my first time using the data.table package.</p>\n<p style=\"padding-left: 30px\">library(data.table)</p>\n<p style=\"padding-left: 30px\">transactions &lt;- fread(&quot;transactions.csv&quot;,integer64=&quot;character&quot;)<br>offers &lt;- fread(&quot;offers.csv&quot;,integer64=&quot;character&quot;)<br>train &lt;- fread(&quot;trainHistory.csv&quot;,integer64=&quot;character&quot;)</p>\n<p style=\"padding-left: 30px\">setkey(offers,offer,category)<br>setkey(train,offer)<br>train &lt;- merge(train,offers,all.x=TRUE)</p>\n<p style=\"padding-left: 30px\">setkey(transactions,id,category)<br>setkey(train,id,category)<br>train.transcat &lt;- transactions[train]<br>dim(train.transcat); head(train.transcat)<br>#[1] 987246 21</p>\n<p style=\"padding-left: 30px\">&nbsp;</p>\n<p>[/quote]</p>\n\n<p>I think the data.table merge doesn't work with integer64</p>\n<p>see for instance: <a href=\"http://r.789695.n4.nabble.com/integer64-group-by-doesn-t-find-all-groups-td4684906.html\">http://r.789695.n4.nabble.com/integer64-group-by-doesn-t-find-all-groups-td4684906.html</a></p>\n<p>I found it does seem to work if you convert the integer64's to double before the merge.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62675",
      "postDate": "01/13/2015 04:29:40",
      "content": "<p>use this :</p>\n<p>awk -F',' '$4 == 9115 || $4 == 9909 || $4 == 3203 || $4 == 5558 || $4 == 4401 || $4 == 1703 || $4 == 1726 || $4 == 3504 || $4 == 3509 || $4 == 9909 || $4 == 5122 || $4 == 5616 || $4 == 5619 || $4 == 2202 || $4 == 2119 || $4 == 6202 || $4 == 5824 || $4 == 799 || $4 == 4517 || $4 == 7205 || $4 == 706' transactions.csv &gt; trans_cat.csv</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "69479",
      "postDate": "04/02/2015 22:22:32",
      "content": "<p>Hi there,</p>\n<p>I starting the project just for practice. But I'm having troubles I dont how to start. Can someone give me some hints.</p>\n<p>I'll appreciate it!</p>\n<p>Thanks,</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "69961",
      "postDate": "04/08/2015 00:36:22",
      "content": "<p>[quote=Daniel Medina;69479]</p>\n<p>Hi there,</p>\n<p>I starting the project just for practice. But I'm having troubles I dont how to start. Can someone give me some hints.</p>\n<p>I'll appreciate it!</p>\n<p>Thanks,</p>\n<p>[/quote]</p>\n<p>You can download Python (http://continuum.io/downloads) and run BreakfastPirate's reduction code to get the transaction dataset down to a ~1GB size.&nbsp;</p>\n<p>To reduce from 1GB down to an even smaller size, you can use the following R code:</p>\n<p>nrow_trans_smaller &lt;- round(nrow(trans)*.05)<br>set.seed(201) <br>rowIndicies_trans_smaller &lt;- sample(1:15349956, size = nrow_trans_smaller, replace = FALSE)<br>trans_smaller &lt;- trans[rowIndicies_trans_smaller, ]<br>write.csv(trans_smaller, &quot;trans_smaller-5%.csv&quot;)</p>\n<p>Hope that helps you get started!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "116222",
      "postDate": "04/22/2016 15:25:20",
      "content": "<p>mark!</p>",
      "rawMarkdown": "mark!",
      "votes": null
    },
    {
      "id": "653454",
      "postDate": "10/20/2019 13:42:22",
      "content": "<p>I am using the following commands . It is throwing the following error \"grep: transactions: No such file or directory\".\nAnd extracted csv was 14.7MB. I am using google colab.</p>",
      "rawMarkdown": "I am using the following commands . It is throwing the following error \"grep: transactions: No such file or directory\".\nAnd extracted csv was 14.7MB. I am using google colab.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 41735,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "04/11/2014 16:10:42",
      "content": "<p>Use,&nbsp;awk -F, '$4 = 706' transactions &gt; trans_cat.csv &nbsp;and so on to avoid junk rows</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41752,
      "author_name": "shuvrobiswas",
      "author_url": "",
      "post_date": "04/11/2014 20:03:51",
      "content": "<p>My machine can't read more than about 50 MB, at once. Just curious what kind of rigs professionals have in place? Do you guys use clusters/hadoop?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41758,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "04/11/2014 22:10:53",
      "content": "<p>You can do most challenges on Kaggle on a budget laptop. SSD helps. 16GB memory helps. Some professionals which I envy have access to clusters and servers, but that is not needed to win a contest. If nothing else, you learn how to be more resourceful (using less resources) and care more about speed.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41764,
      "author_name": "breakfastpirate",
      "author_url": "",
      "post_date": "04/11/2014 22:34:09",
      "content": "<p>I agree with Triskelion. &nbsp;I am able to use my 8GB laptop for most Kaggle contests. If there is a contest that requires a large amount of memory, I sometimes rent an Amazon EC2 instance with 32GB for a couple weeks.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41774,
      "author_name": "breakfastpirate",
      "author_url": "",
      "post_date": "04/12/2014 02:29:31",
      "content": "<p>I've also found that another useful subset is: only transactions where the company was a company on at least one of the offers. &nbsp;This was also about 1GB. &nbsp;There is obviously some overlap between this and the category subset. &nbsp;What would be best would be to have the union of these without duplicates.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41820,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "04/12/2014 22:56:44",
      "content": "<p>In Python to reduce from 20GB to about 1GB (349.655.789 lines to 15.349.956 lines) or &quot;the category subset&quot; as BreakfastPirate calls it:</p>\n<p><code>from datetime import datetime</code></p>\n<p><code></code><code>loc_offers = &quot;kaggle_shop\\\\offers.csv&quot;<br>loc_transactions = &quot;kaggle_shop\\\\transactions.csv&quot;<br>loc_reduced = &quot;kaggle_shop\\\\reduced2.csv&quot; # will be created</code></p>\n<p><code><code>def&nbsp;</code>reduce_data(loc_offers, loc_transactions, loc_reduced):</code></p>\n<p><code>&nbsp; start = datetime.now()<br>&nbsp; #get all categories on offer in a dict<br>&nbsp; offers = {}<br>&nbsp; for e, line in enumerate( open(loc_offers) ):<br>&nbsp; &nbsp; offers[ line.split(&quot;,&quot;)[1] ] = 1<br>&nbsp; #open output file<br>&nbsp; with open(loc_reduced, &quot;wb&quot;) as outfile:<br>&nbsp; &nbsp; #go through transactions file and reduce<br>&nbsp; &nbsp; reduced = 0<br>&nbsp; &nbsp; for e, line in enumerate( open(loc_transactions) ):<br>&nbsp; &nbsp; &nbsp; if e == 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; outfile.write( line ) #print header<br>&nbsp; &nbsp; &nbsp; else:<br>&nbsp; &nbsp; &nbsp; &nbsp; #only write when category in offers dict<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if line.split(&quot;,&quot;)[3] in offers:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outfile.write( line )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reduced += 1<br>&nbsp; &nbsp; &nbsp; #progress<br>&nbsp; &nbsp; &nbsp; if e % 5000000 == 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; print e, reduced, datetime.now() - start<br>&nbsp; print e, reduced, datetime.now() - start</code></p>\n<p><code>reduce_data(loc_offers, loc_transactions, loc_reduced)</code></p>\n<p>if you want to reduce the data with company, change:</p>\n<p><code>offers[ line.split(&quot;,&quot;)[1] ] = 1&nbsp;<br></code></p>\n<p>to:</p>\n<p><code>offers[ line.split(&quot;,&quot;)[3] ] = 1</code></p>\n<p>and:</p>\n<p><code>if line.split(&quot;,&quot;)[3] in offers</code></p>\n<p>to:</p>\n<p><code>if line.split(&quot;,&quot;)[4] in offers</code></p>\n<p>The category+company union is about 27 million lines (1.6Gb).</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41821,
      "author_name": "piotrkuchta",
      "author_url": "",
      "post_date": "04/12/2014 23:11:24",
      "content": "<p>Python is good for these kind of tasks - the standard CPython is pretty slow, but if your script uses only standard libraries and doesn't use numpy, sklearn, etc. then you should be able to run it with pypy, which is really fast, can be easily an order of magnitude faster than CPython. I think Triskelion's script would take about 10 minutes to process the transactions data on an average PC (I've written something similar to reduce the amount of data).</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41822,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "04/12/2014 23:20:24",
      "content": "<p>Yup, about 10 minutes to write, about 10 minutes to run. Not the fastest, but should work on any PC (takes max 6mb memory).</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41842,
      "author_name": "nizhibitsky",
      "author_url": "",
      "post_date": "04/13/2014 11:32:55",
      "content": "<p>It takes exactly 3:29 with both PyPy and CPython to run that filtering script on my laptop.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 41850,
      "author_name": "jfkingiii",
      "author_url": "",
      "post_date": "04/13/2014 16:44:47",
      "content": "<p>Transaction file summary statistics:</p>\n\n<p>349655789 records</p>\n<p>total purchasequantity&nbsp;584540514</p>\n<p>total purchaseamount&nbsp;1568488398</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 42660,
      "author_name": "webscale",
      "author_url": "",
      "post_date": "04/22/2014 01:09:09",
      "content": "<p>My recommendation - Download Datameer and get 15 days trial edition.</p>\n<p>Create one workbook in datameer that merges the offers + trainhistory&nbsp;+ transactions.</p>\n<p>You are ready to go</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43083,
      "author_name": "tonidm",
      "author_url": "",
      "post_date": "04/26/2014 16:03:13",
      "content": "<p>hi! and how did you do that?</p>\n<p>which variables did you use to merge the 3 tables??? the relation is 1to1??</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43097,
      "author_name": "zachmayer",
      "author_url": "",
      "post_date": "04/26/2014 19:04:49",
      "content": "<p>[quote=neeraj;42660]</p>\n<p>My recommendation - Download Datameer and get 15 days trial edition.</p>\n<p>Create one workbook in datameer that merges the offers + trainhistory + transactions.</p>\n<p>You are ready to go</p>\n<p>[/quote]</p>\n<p>Why pay for commercial software when R and python are free?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43098,
      "author_name": "jamespaul",
      "author_url": "",
      "post_date": "04/26/2014 19:21:12",
      "content": "<p>Data sets of this size, might be larger than the memory of the computer could hold. Open source R will may fail&nbsp;in such scenarios. (Unless you use packages like ff/bigmemory/bigglm). Revolution R Enterprise, uses external memory algorithms have no data limits, and is easier to use than ff/bigmemory/bigglm.</p>\n<p>It is available for Kaggle users for free for participating in Kaggle contests. Download here</p>\n<p>http://info.revolutionanalytics.com/Kaggle.html</p>\n<p>[post edited to incorporate comments from Zach]</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43103,
      "author_name": "zachmayer",
      "author_url": "",
      "post_date": "04/26/2014 20:18:18",
      "content": "<p>[quote=James Paul;43098]</p>\n<p>Data sets of this size, might be larger than the memory of the computer could hold. Open source R will fail in such scenarios. Revolution R Enteprise, uses external memory algorithms have no data limits.</p>\n<p>It is available for Kaggle users for free for participating in Kaggle contests. Download here</p>\n<p>http://info.revolutionanalytics.com/Kaggle.html</p>\n<p>[/quote]</p>\n<p>The dataset for this competition will fit in memory on a computer with 16 gigs of RAM. &nbsp;Furthermore, open source R can use out-of-memory algorithms, for example with the <a href=\"http://www.bigmemory.org/\">bigmemory</a>&nbsp;and <a href=\"http://cran.r-project.org/web/packages/ff/index.html\">ff</a>&nbsp;packages.</p>\n<p>Don't get me wrong, I love Revolution R: I have the t-shirt and foreach is one of my favorite packages. &nbsp;But open-source R is definitely up for this challenge.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43416,
      "author_name": "vateeshc",
      "author_url": "",
      "post_date": "05/01/2014 01:20:18",
      "content": "<p>Thank you for referring to revolutionanalytics (RA). I downloaded their software and attempted to import the entire transactions file. But ran out of memory as the import was being handled locally. I have a windows xp 4GB RAM laptop. Does anyone know if we can leverage RA's remote computing capability for kaggle comps? and if so, will appreciate any info on how to do this. On the side I am also giving the ff package a go as well but again limited by memory issues. And I am also aware of other opportunities to scale down data size from previous forum contributions.&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43417,
      "author_name": "jamespaul",
      "author_url": "",
      "post_date": "05/01/2014 01:40:26",
      "content": "<p>Please contact support@revolutionanalytics.com with your specific error. I have a 16GB laptop and I imported the data easily. I used the following commands to import to the Extended Data Frame format.</p>\n<p>offers&lt;-rxImport(inData=&quot;offers.csv&quot;, outFile=&quot;offers.xdf&quot;, stringsAsFactors=TRUE, missingValueString=&quot;M&quot;)<br>trainHistory&lt;-rxImport(inData=&quot;trainHistory.csv&quot;, outFile=&quot;trainHistory.xdf&quot;, stringsAsFactors=TRUE, missingValueString=&quot;M&quot;)<br>tx&lt;-rxImport(inData=&quot;transactions.csv&quot;, outFile=&quot;tx.xdf&quot;, stringsAsFactors=TRUE, missingValueString=&quot;M&quot;) (It does take time to import this one)</p>\n<p>You can merge/combine the .xdf files to proceed with the next steps. (Use rxDataStep command)</p>\n<p>The user guide has a number of commonly used scenarios in manipulating data.</p>\n<p>You can also use Revolution R Enterprise in AWS. (You can get upto 64GB RAM machines)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43489,
      "author_name": "zachmayer",
      "author_url": "",
      "post_date": "05/02/2014 01:57:55",
      "content": "<p>&quot;fread&quot; from the data.table package is also sufficient to load the full dataset in open source R (at least on a mac).</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43522,
      "author_name": "manueldiaz",
      "author_url": "",
      "post_date": "05/02/2014 18:21:10",
      "content": "<p>I have a windows xp laptop 2GB RAM, and I get good results in Kaggle competitions ... even a winning price ... I use speed (Kaggle user license) and python ...</p>\n<p>I think this enough for this competition, but needs a careful treatment of data ...</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43626,
      "author_name": "neilpatel",
      "author_url": "",
      "post_date": "05/03/2014 19:34:08",
      "content": "<p>@Triskelion</p>\n<p>Great reduction code sir!</p>\n<p>I ran it in a little over 6 minutes and reduced down to 1GB. &nbsp;I was wondering if you can you provide an explanation, line by line what is going on for the group? I am new to python but I understand some of the basics.&nbsp;</p>\n<p>Basically, I wanted to know why this works and something like just usingn pandas and dataframes crashes. &nbsp;Is it because you're only doing a pivot table and filtering on 5million records at a time?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 43646,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "05/03/2014 23:32:04",
      "content": "<p>[quote=Neil Patel;43626]</p>\n<p>@Triskelion</p>\n<p>Great reduction code sir!</p>\n<p>I ran it in a little over 6 minutes and reduced down to 1GB. &nbsp;I was wondering if you can you provide an explanation, line by line what is going on for the group? I am new to python but I understand some of the basics.&nbsp;</p>\n<p>Basically, I wanted to know why this works and something like just usingn pandas and dataframes crashes. &nbsp;Is it because you're only doing a pivot table and filtering on 5million records at a time?</p>\n<p>[/quote]</p>\n<p>Ty sir. I will provide an explanation, line by line, but do keep in mind that I am new to Python too, you may just be a tad newer.&nbsp;</p>\n<p>Why this works and not using pandas, I think is because you try to create a dataframe of the entire dataset (before reducing). With ~8GB mem you probably want to read the data line by line or in chunks. It is possible that Pandas is faster than my code if you make smart use of '<a href=\"http://pandas.pydata.org/pandas-docs/stable/io.html#io-chunking\">chunksize</a>' and possibly an iterator.</p>\n<p>BTW: Are you Neil Patel from&nbsp;Seattle? If so, I am a big fan, sir!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44373,
      "author_name": "user191111",
      "author_url": "",
      "post_date": "05/11/2014 13:37:20",
      "content": "<p>Thanks</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44563,
      "author_name": "nolanwilson",
      "author_url": "",
      "post_date": "05/14/2014 23:37:18",
      "content": "<p>Triskelion awesome starter code. &nbsp;Interestingly I was implementing my own version of this code but noticed it was running substantially slower than original. &nbsp;Turns out, I was defining the &quot;offer&quot; as an array rather than a dictionary which made a huge difference in the speed of the code. &nbsp;I am relatively new to python and was wondering if anyone could comment as to why this occurs.</p>\n\n<p>offer = [] #runs slow</p>\n<p>offer = {} # runs quickly</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44567,
      "author_name": "user191111",
      "author_url": "",
      "post_date": "05/15/2014 01:55:50",
      "content": "<p>How do you figure out that the performance issue of your program is due to list? (Did you use a profiler or ...)</p>\n<p>Since offer.csv is not large, I doubt whether using list to store the offers will slow down the program substantially</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44575,
      "author_name": "nolanwilson",
      "author_url": "",
      "post_date": "05/15/2014 04:11:33",
      "content": "<p>There is a time stamp within the code. &nbsp;It also reports the row which it is on. &nbsp;It clearly was taking longer to run the script based on observation. &nbsp;You are correct, offer.csv is small; however transactions.csv is very large. &nbsp;I believe the issue to be how the created dictionary from offer.csv&nbsp;is used to cross reference against the data in the transaction file when the for loop to check to see if some value from offer is found within the transactions file.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44577,
      "author_name": "user191111",
      "author_url": "",
      "post_date": "05/15/2014 06:35:57",
      "content": "<p>Hmm, maybe you are right.</p>\n<p>But why not just using dict? Don't waste your time on list and dict, after all, it's not the major part of the competition</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44619,
      "author_name": "nolanwilson",
      "author_url": "",
      "post_date": "05/15/2014 15:54:19",
      "content": "<p>I ended up using a dict for the code, but it took me a little while to figure out that was the issue. &nbsp;I am mostly wondering why the code performs differently since the data within the dict or list is the same size. &nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44621,
      "author_name": "jkalmeij",
      "author_url": "",
      "post_date": "05/15/2014 16:04:00",
      "content": "<p>You need to provide more information (i.e. link to your code) if you want an answer.</p>\n<p>You can not generally replace a list with a dict (and vice versa), since their construction will differ. You might be using:</p>\n<p>&nbsp; &nbsp; if <em>something</em> in offers:</p>\n<p>This will be O(1) for dict, and O(n) for list. That is, to answer if some key is in a dictionary takes 1 unit of time, and to answer if some key is in a list takes some amount of time proportional to the amount of elements in the list.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44677,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "05/16/2014 18:42:04",
      "content": "<p>[quote=Nolan Wilson;44563]</p>\n<p>I am relatively new to python and was wondering if anyone could comment as to why this occurs.</p>\n<p>offer = [] #runs slow</p>\n<p>offer = {} # runs quickly</p>\n<p>[/quote]</p>\n<p>&quot;If key in dictionary&quot;</p>\n<p>is faster than:</p>\n<p>&quot;If key in list&quot;.</p>\n<p>From https://wiki.python.org/moin/PythonSpeed:</p>\n<p><em>Membership testing with sets and dictionaries is much faster, O(1), than searching sequences, O(n). When testing &quot;a in b&quot;, b should be a set or dictionary instead of a list or tuple.</em></p>\n<p>Why this is? I think this is (not an expert) because Python dictionaries are <a href=\"http://en.wikipedia.org/wiki/Hash_table\">hash tables</a>&nbsp;or hash mappings. Notes on the original implementation <a href=\"https://mail.python.org/pipermail/python-list/2000-March/048085.html\">here</a>. Like the above quote on Python speed best practices, checking if an item is a member of a hash table is near instant, in the case of a list, it has to check every member if it is the same, and so has to traverse the entire list in the worst case scenario (when the item is not in the list).</p>\n<p>Source for DictObject &quot;with comments&quot; at:&nbsp;http://svn.python.org/view/python/trunk/Objects/dictobject.c?view=markup</p>\n<p>Since the membership check occurs in the loop that scans every transaction record, it is run ~350million times. That extra&nbsp;0.00001 second it takes for a check&nbsp;may then turn into an hour.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44678,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "05/16/2014 18:48:27",
      "content": "<p>dict is always faster than the list in python (comparable for small data)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44771,
      "author_name": "nubeee",
      "author_url": "",
      "post_date": "05/18/2014 07:22:25",
      "content": "<p>Hello, do you know if it is possible to reduce the file size only using R? I don't have Unix. :(</p>\n<p>I tried to read the R transactions file, however it failed as the file is too big to read. :(</p>\n\n<p>Thanks</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 44793,
      "author_name": "breakfastpirate",
      "author_url": "",
      "post_date": "05/18/2014 19:47:20",
      "content": "<p>There are Unix commands available for Windows. &nbsp;Here is one source:&nbsp;http://unxutils.sourceforge.net/</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 45982,
      "author_name": "chitrasen",
      "author_url": "",
      "post_date": "05/21/2014 10:33:07",
      "content": "<p>[quote=Nubee;44771]</p>\n<p>Hello, do you know if it is possible to reduce the file size only using R? I don't have Unix. :(</p>\n<p>I tried to read the R transactions file, however it failed as the file is too big to read. :(</p>\n<p>Thanks</p>\n<p>[/quote]</p>\n<p>Option 1, split the file and process them in R and merge the results</p>\n<p>Option 2, use read.table with skip and nrows multiple times and merger the results.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49266,
      "author_name": "swhardy",
      "author_url": "",
      "post_date": "06/18/2014 03:20:48",
      "content": "<p>I think the R code below does the same thing as the data reduction being discussed in this thread, i.e. create a subset of transactions containing only the category corresponding to the offer which was received. But the result has 987,246 rows, considerably less than the 15.349.956 that Triskelion got with his Python code.&nbsp; As far as I know this code does not pick up categories corresponding to offers received by other customers. Perhaps the Python code does? Either that or this code is not working like I think it should. This is my first time using the data.table package.</p>\n\n<p style=\"padding-left: 30px\">library(data.table)</p>\n<p style=\"padding-left: 30px\">transactions &lt;- fread(&quot;transactions.csv&quot;,integer64=&quot;character&quot;)<br>offers &lt;- fread(&quot;offers.csv&quot;,integer64=&quot;character&quot;)<br>train &lt;- fread(&quot;trainHistory.csv&quot;,integer64=&quot;character&quot;)</p>\n<p style=\"padding-left: 30px\">setkey(offers,offer,category)<br>setkey(train,offer)<br>train &lt;- merge(train,offers,all.x=TRUE)</p>\n<p style=\"padding-left: 30px\">setkey(transactions,id,category)<br>setkey(train,id,category)<br>train.transcat &lt;- transactions[train]<br>dim(train.transcat); head(train.transcat)<br>#[1] 987246 21</p>\n<p style=\"padding-left: 30px\">&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49345,
      "author_name": "shreedharpawar",
      "author_url": "",
      "post_date": "06/20/2014 18:37:17",
      "content": "<p>I have a laptop with 4 gigs of RAM and I am trying to read the transaction.csv file using the read.csv.ffdf command.... &quot;read.csv.ffdf(file=&quot;transactions.csv&quot;, header=TRUE, VERBOSE=TRUE, nrows=20000, next.rows=500000, colClasses=NA)&quot;....&nbsp; I can read rows starting from 1 itself to whatever no. I wish which is not a problem&nbsp;but I am not able to set specific no. of rows &nbsp;as arguments in this command... like I want to read no. of rows starting from 10000 to 20000... please suggest some other command where I can set the no. of row to start with... Also I dont I have an access to UNIX...!&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50211,
      "author_name": "analyticsanimal",
      "author_url": "",
      "post_date": "07/09/2014 16:00:58",
      "content": "<p>you can also rent an EC2 HANA system (in-memory database from SAP), load the data and do everything via SQL.</p>\n<p>Queries on the 300Mio rows run in sub-second response times... :-)</p>\n\n<p>br, WM</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50258,
      "author_name": "julesvanligtenberg",
      "author_url": "",
      "post_date": "07/10/2014 09:41:17",
      "content": "<p>[quote=Sarah Hardy;49266]</p>\n<p>I think the R code below does the same thing as the data reduction being discussed in this thread, i.e. create a subset of transactions containing only the category corresponding to the offer which was received. But the result has 987,246 rows, considerably less than the 15.349.956 that Triskelion got with his Python code.&nbsp; As far as I know this code does not pick up categories corresponding to offers received by other customers. Perhaps the Python code does? Either that or this code is not working like I think it should. This is my first time using the data.table package.</p>\n<p style=\"padding-left: 30px\">library(data.table)</p>\n<p style=\"padding-left: 30px\">transactions &lt;- fread(&quot;transactions.csv&quot;,integer64=&quot;character&quot;)<br>offers &lt;- fread(&quot;offers.csv&quot;,integer64=&quot;character&quot;)<br>train &lt;- fread(&quot;trainHistory.csv&quot;,integer64=&quot;character&quot;)</p>\n<p style=\"padding-left: 30px\">setkey(offers,offer,category)<br>setkey(train,offer)<br>train &lt;- merge(train,offers,all.x=TRUE)</p>\n<p style=\"padding-left: 30px\">setkey(transactions,id,category)<br>setkey(train,id,category)<br>train.transcat &lt;- transactions[train]<br>dim(train.transcat); head(train.transcat)<br>#[1] 987246 21</p>\n<p style=\"padding-left: 30px\">&nbsp;</p>\n<p>[/quote]</p>\n\n<p>I think the data.table merge doesn't work with integer64</p>\n<p>see for instance: <a href=\"http://r.789695.n4.nabble.com/integer64-group-by-doesn-t-find-all-groups-td4684906.html\">http://r.789695.n4.nabble.com/integer64-group-by-doesn-t-find-all-groups-td4684906.html</a></p>\n<p>I found it does seem to work if you convert the integer64's to double before the merge.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62675,
      "author_name": "vikasveshishth",
      "author_url": "",
      "post_date": "01/13/2015 04:29:40",
      "content": "<p>use this :</p>\n<p>awk -F',' '$4 == 9115 || $4 == 9909 || $4 == 3203 || $4 == 5558 || $4 == 4401 || $4 == 1703 || $4 == 1726 || $4 == 3504 || $4 == 3509 || $4 == 9909 || $4 == 5122 || $4 == 5616 || $4 == 5619 || $4 == 2202 || $4 == 2119 || $4 == 6202 || $4 == 5824 || $4 == 799 || $4 == 4517 || $4 == 7205 || $4 == 706' transactions.csv &gt; trans_cat.csv</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 69479,
      "author_name": "danielmedina",
      "author_url": "",
      "post_date": "04/02/2015 22:22:32",
      "content": "<p>Hi there,</p>\n<p>I starting the project just for practice. But I'm having troubles I dont how to start. Can someone give me some hints.</p>\n<p>I'll appreciate it!</p>\n<p>Thanks,</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 69961,
      "author_name": "dluzansky",
      "author_url": "",
      "post_date": "04/08/2015 00:36:22",
      "content": "<p>[quote=Daniel Medina;69479]</p>\n<p>Hi there,</p>\n<p>I starting the project just for practice. But I'm having troubles I dont how to start. Can someone give me some hints.</p>\n<p>I'll appreciate it!</p>\n<p>Thanks,</p>\n<p>[/quote]</p>\n<p>You can download Python (http://continuum.io/downloads) and run BreakfastPirate's reduction code to get the transaction dataset down to a ~1GB size.&nbsp;</p>\n<p>To reduce from 1GB down to an even smaller size, you can use the following R code:</p>\n<p>nrow_trans_smaller &lt;- round(nrow(trans)*.05)<br>set.seed(201) <br>rowIndicies_trans_smaller &lt;- sample(1:15349956, size = nrow_trans_smaller, replace = FALSE)<br>trans_smaller &lt;- trans[rowIndicies_trans_smaller, ]<br>write.csv(trans_smaller, &quot;trans_smaller-5%.csv&quot;)</p>\n<p>Hope that helps you get started!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 116222,
      "author_name": "leyue260351",
      "author_url": "",
      "post_date": "04/22/2016 15:25:20",
      "content": "<p>mark!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 653454,
      "author_name": "subho22",
      "author_url": "",
      "post_date": "10/20/2019 13:42:22",
      "content": "<p>I am using the following commands . It is throwing the following error \"grep: transactions: No such file or directory\".\nAnd extracted csv was 14.7MB. I am using google colab.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "41729": "",
    "41735": "",
    "41752": "",
    "41758": "",
    "41764": "",
    "41774": "",
    "41820": "",
    "41821": "",
    "41822": "",
    "41842": "",
    "41850": "",
    "42660": "",
    "43083": "",
    "43097": "",
    "43098": "",
    "43103": "",
    "43416": "",
    "43417": "",
    "43489": "",
    "43522": "",
    "43626": "",
    "43646": "",
    "44373": "",
    "44563": "",
    "44567": "",
    "44575": "",
    "44577": "",
    "44619": "",
    "44621": "",
    "44677": "",
    "44678": "",
    "44771": "",
    "44793": "",
    "45982": "",
    "49266": "",
    "49345": "",
    "50211": "",
    "50258": "",
    "62675": "",
    "69479": "",
    "69961": "",
    "116222": "mark!",
    "653454": "I am using the following commands . It is throwing the following error \"grep: transactions: No such file or directory\".\nAnd extracted csv was 14.7MB. I am using google colab."
  },
  "source": "meta"
}