{
  "id": 9953,
  "title": "Can't read after 1562936th row in training data",
  "url": "/competitions/avito-prohibited-content/discussion/9953",
  "author_name": "",
  "post_date": "2014-08-05T15:26:48.680Z",
  "votes": 2,
  "comment_count": 17,
  "views": 5146,
  "content": "<p>wc -l avito_trian.tsv indicates that there are ~4m training points. However, my code which is based on the provided python code seems fail to read training data after&nbsp;1562936th row. Here it is:</p>\n<p><code> with open(tsv_file) as tsvReader:<br>&nbsp; &nbsp; itemReader = DictReader(tsvReader, delimiter='\\t', quotechar = '&quot;')<br>&nbsp; &nbsp; for i, item in enumerate(itemReader):<br>&nbsp; &nbsp; &nbsp; &nbsp; item_dict = {featureName:featureValue.decode('utf-8') \\<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for featureName,featureValue in item.iteritems() \\<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if featureValue is not None}</code></p>\n<p>In specific, for the&nbsp;1562936th row, some keys, e.g., is_blocked and prices is even missing in&nbsp;item_dict. Does&nbsp;anyone know what goes wrong?</p>",
  "messages": [
    {
      "id": "51635",
      "postDate": "08/05/2014 15:26:48",
      "content": "<p>wc -l avito_trian.tsv indicates that there are ~4m training points. However, my code which is based on the provided python code seems fail to read training data after&nbsp;1562936th row. Here it is:</p>\n<p><code> with open(tsv_file) as tsvReader:<br>&nbsp; &nbsp; itemReader = DictReader(tsvReader, delimiter='\\t', quotechar = '&quot;')<br>&nbsp; &nbsp; for i, item in enumerate(itemReader):<br>&nbsp; &nbsp; &nbsp; &nbsp; item_dict = {featureName:featureValue.decode('utf-8') \\<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for featureName,featureValue in item.iteritems() \\<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if featureValue is not None}</code></p>\n<p>In specific, for the&nbsp;1562936th row, some keys, e.g., is_blocked and prices is even missing in&nbsp;item_dict. Does&nbsp;anyone know what goes wrong?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51636",
      "postDate": "08/05/2014 15:27:58",
      "content": "<p>bummer :P</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51637",
      "postDate": "08/05/2014 15:34:08",
      "content": "<p>Still, I was happy to find out that my model has actually been&nbsp;trained on ~40% data, which makes me think there might be some room for improvement...</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51638",
      "postDate": "08/05/2014 15:35:18",
      "content": "<p>well, it works for me..</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51650",
      "postDate": "08/05/2014 18:55:04",
      "content": "<p>Beware that &quot;wc -l&quot; gives a line count. .csv or .tsv files&nbsp;could&nbsp;have samples with text that span multiple lines:</p>\n<p>&quot;0&quot;,&quot;15&quot;,&quot;description \\n\\n buy this!&quot;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51653",
      "postDate": "08/05/2014 23:16:24",
      "content": "<p>[quote=Triskelion;51650]</p>\n<p>Beware that &quot;wc -l&quot; gives a line count. .csv or .tsv files&nbsp;could&nbsp;have samples with text that span multiple lines:</p>\n<p>&quot;0&quot;,&quot;15&quot;,&quot;description \\n\\n buy this!&quot;</p>\n<p>[/quote]</p>\n<p>But it gives the right number of the testing set, i.e., 1351243. PS. what's the number of training data on you side?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51662",
      "postDate": "08/06/2014 10:23:30",
      "content": "<p>1.562.936 samples in train.</p>\n<p>1.562.937 lines in train.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51663",
      "postDate": "08/06/2014 10:36:51",
      "content": "<p>omg! you have two train sets!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51664",
      "postDate": "08/06/2014 10:37:34",
      "content": "<p>[quote=Triskelion;51662]</p>\n<p>1.562.936 samples in train.</p>\n<p>1.562.937 lines in train.</p>\n<p>[/quote]</p>\n<p>LOL... I am now confused why Zygmunt said there are 4m points here:&nbsp;http://www.kaggle.com/c/avito-prohibited-content/forums/t/9667/millions-of-training-examples/50147#post50147</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51669",
      "postDate": "08/06/2014 12:27:41",
      "content": "<p>I have&nbsp;3995803 samples in train and&nbsp;1351242 in test. Data loaded just by pandas.read_csv(&quot;./avito_train.tsv&quot;, sep=&quot;\\t&quot;, encoding='utf8') without any problem.</p>\n<p>Raw data has:</p>\n<p># cat avito_train.tsv | wc -l<br>3995804</p>\n<p># cat avito_test.tsv | wc -l<br>1351243</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51670",
      "postDate": "08/06/2014 12:30:56",
      "content": "<p>By the way,&nbsp;</p>\n<p># cat test<br>&quot;0&quot;,&quot;15&quot;,&quot;description \\n\\n buy this!&quot;<br># cat test | wc -l<br>1</p>\n<p>*upd: sorry for duplicating =)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51671",
      "postDate": "08/06/2014 12:38:39",
      "content": "<p>I think I made a mistake similar to yr. Just looking at the file sizes of the train and test set, the train set should be more like 4 million samples.</p>\n<p>Perhaps there is some bug or incorrect usage of csv.DictReader. Or Pandas has a better parser for edge cases. Anyway it is strange.</p>\n<p>pd.read_csv gives me 3.995.803 records too.</p>\n<p>Thanks Mikhail and yr, I now have more data to train on, will post here if it makes any difference.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51672",
      "postDate": "08/06/2014 12:41:05",
      "content": "<p>[quote=Mikhail Trofimov;51670]</p>\n<p>By the way,&nbsp;</p>\n<p># cat test<br>&quot;0&quot;,&quot;15&quot;,&quot;description \\n\\n buy this!&quot;<br># cat test | wc -l<br>1</p>\n<p>*upd: sorry for duplicating =)</p>\n<p>[/quote]</p>\n<p>It is not happening here, but beware that &quot;wc -l&quot; is not always reliable to count samples in .csv files. For example the StackOverflow dataset had multi-line text columns:</p>\n<p>&quot;0&quot;,&quot;15&quot;,&quot;description</p>\n<p>buy this!&quot;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51673",
      "postDate": "08/06/2014 13:07:19",
      "content": "<p>Thanks all you guys! I will try pandas then. Hopefully it will make a difference with more data :-)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51674",
      "postDate": "08/06/2014 13:34:11",
      "content": "<p>yr, can you run the following:</p>\n<p><code>print len(open(&quot;avito_train.tsv&quot;).readlines())<br></code></p>\n<p>and report back the number and your OS and Python version?</p>\n<p>Windows 7, Python 2.7: 1.562.938</p>\n<p>Mac OSX 10, Python 2.7: 3.995.804</p>\n<p>Is this an encoding issue which Pandas auto-solves? Never heard about encoding issues for line counts in this way.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51675",
      "postDate": "08/06/2014 13:59:27",
      "content": "<p>Here it is:</p>\n<p>Windows 7 64bit, Python 2.7.6 (Anaconda 1.9.0 (64-bit)): 1,562,938</p>\n<p>But I am able to reproduce the benchmark. It might also be the reason while others can not:&nbsp;http://www.kaggle.com/c/avito-prohibited-content/forums/t/9722/sample-code-different-from-benchmark</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51708",
      "postDate": "08/07/2014 11:49:57",
      "content": "<p>@Triskelion,</p>\n<p>Try this:</p>\n<p><code>len((open(train_file_csv,&quot;rb&quot;).readlines()))</code></p>\n<p>It now gives&nbsp;3,995,804.</p>\n<p>I learned it from this post:&nbsp;http://stackoverflow.com/questions/1170214/pythons-csv-writer-produces-wrong-line-terminator</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51733",
      "postDate": "08/08/2014 02:18:34",
      "content": "<p>Seems more data does help:&nbsp;0.97691 -&gt;&nbsp;0.98000 :-)</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 51636,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "08/05/2014 15:27:58",
      "content": "<p>bummer :P</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51637,
      "author_name": "chenglongchen",
      "author_url": "",
      "post_date": "08/05/2014 15:34:08",
      "content": "<p>Still, I was happy to find out that my model has actually been&nbsp;trained on ~40% data, which makes me think there might be some room for improvement...</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51638,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "08/05/2014 15:35:18",
      "content": "<p>well, it works for me..</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51650,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "08/05/2014 18:55:04",
      "content": "<p>Beware that &quot;wc -l&quot; gives a line count. .csv or .tsv files&nbsp;could&nbsp;have samples with text that span multiple lines:</p>\n<p>&quot;0&quot;,&quot;15&quot;,&quot;description \\n\\n buy this!&quot;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51653,
      "author_name": "chenglongchen",
      "author_url": "",
      "post_date": "08/05/2014 23:16:24",
      "content": "<p>[quote=Triskelion;51650]</p>\n<p>Beware that &quot;wc -l&quot; gives a line count. .csv or .tsv files&nbsp;could&nbsp;have samples with text that span multiple lines:</p>\n<p>&quot;0&quot;,&quot;15&quot;,&quot;description \\n\\n buy this!&quot;</p>\n<p>[/quote]</p>\n<p>But it gives the right number of the testing set, i.e., 1351243. PS. what's the number of training data on you side?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51662,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "08/06/2014 10:23:30",
      "content": "<p>1.562.936 samples in train.</p>\n<p>1.562.937 lines in train.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51663,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "08/06/2014 10:36:51",
      "content": "<p>omg! you have two train sets!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51664,
      "author_name": "chenglongchen",
      "author_url": "",
      "post_date": "08/06/2014 10:37:34",
      "content": "<p>[quote=Triskelion;51662]</p>\n<p>1.562.936 samples in train.</p>\n<p>1.562.937 lines in train.</p>\n<p>[/quote]</p>\n<p>LOL... I am now confused why Zygmunt said there are 4m points here:&nbsp;http://www.kaggle.com/c/avito-prohibited-content/forums/t/9667/millions-of-training-examples/50147#post50147</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51669,
      "author_name": "mikhailtrofimov",
      "author_url": "",
      "post_date": "08/06/2014 12:27:41",
      "content": "<p>I have&nbsp;3995803 samples in train and&nbsp;1351242 in test. Data loaded just by pandas.read_csv(&quot;./avito_train.tsv&quot;, sep=&quot;\\t&quot;, encoding='utf8') without any problem.</p>\n<p>Raw data has:</p>\n<p># cat avito_train.tsv | wc -l<br>3995804</p>\n<p># cat avito_test.tsv | wc -l<br>1351243</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51670,
      "author_name": "mikhailtrofimov",
      "author_url": "",
      "post_date": "08/06/2014 12:30:56",
      "content": "<p>By the way,&nbsp;</p>\n<p># cat test<br>&quot;0&quot;,&quot;15&quot;,&quot;description \\n\\n buy this!&quot;<br># cat test | wc -l<br>1</p>\n<p>*upd: sorry for duplicating =)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51671,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "08/06/2014 12:38:39",
      "content": "<p>I think I made a mistake similar to yr. Just looking at the file sizes of the train and test set, the train set should be more like 4 million samples.</p>\n<p>Perhaps there is some bug or incorrect usage of csv.DictReader. Or Pandas has a better parser for edge cases. Anyway it is strange.</p>\n<p>pd.read_csv gives me 3.995.803 records too.</p>\n<p>Thanks Mikhail and yr, I now have more data to train on, will post here if it makes any difference.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51672,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "08/06/2014 12:41:05",
      "content": "<p>[quote=Mikhail Trofimov;51670]</p>\n<p>By the way,&nbsp;</p>\n<p># cat test<br>&quot;0&quot;,&quot;15&quot;,&quot;description \\n\\n buy this!&quot;<br># cat test | wc -l<br>1</p>\n<p>*upd: sorry for duplicating =)</p>\n<p>[/quote]</p>\n<p>It is not happening here, but beware that &quot;wc -l&quot; is not always reliable to count samples in .csv files. For example the StackOverflow dataset had multi-line text columns:</p>\n<p>&quot;0&quot;,&quot;15&quot;,&quot;description</p>\n<p>buy this!&quot;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51673,
      "author_name": "chenglongchen",
      "author_url": "",
      "post_date": "08/06/2014 13:07:19",
      "content": "<p>Thanks all you guys! I will try pandas then. Hopefully it will make a difference with more data :-)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51674,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "08/06/2014 13:34:11",
      "content": "<p>yr, can you run the following:</p>\n<p><code>print len(open(&quot;avito_train.tsv&quot;).readlines())<br></code></p>\n<p>and report back the number and your OS and Python version?</p>\n<p>Windows 7, Python 2.7: 1.562.938</p>\n<p>Mac OSX 10, Python 2.7: 3.995.804</p>\n<p>Is this an encoding issue which Pandas auto-solves? Never heard about encoding issues for line counts in this way.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51675,
      "author_name": "chenglongchen",
      "author_url": "",
      "post_date": "08/06/2014 13:59:27",
      "content": "<p>Here it is:</p>\n<p>Windows 7 64bit, Python 2.7.6 (Anaconda 1.9.0 (64-bit)): 1,562,938</p>\n<p>But I am able to reproduce the benchmark. It might also be the reason while others can not:&nbsp;http://www.kaggle.com/c/avito-prohibited-content/forums/t/9722/sample-code-different-from-benchmark</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51708,
      "author_name": "chenglongchen",
      "author_url": "",
      "post_date": "08/07/2014 11:49:57",
      "content": "<p>@Triskelion,</p>\n<p>Try this:</p>\n<p><code>len((open(train_file_csv,&quot;rb&quot;).readlines()))</code></p>\n<p>It now gives&nbsp;3,995,804.</p>\n<p>I learned it from this post:&nbsp;http://stackoverflow.com/questions/1170214/pythons-csv-writer-produces-wrong-line-terminator</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51733,
      "author_name": "chenglongchen",
      "author_url": "",
      "post_date": "08/08/2014 02:18:34",
      "content": "<p>Seems more data does help:&nbsp;0.97691 -&gt;&nbsp;0.98000 :-)</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "51635": "",
    "51636": "",
    "51637": "",
    "51638": "",
    "51650": "",
    "51653": "",
    "51662": "",
    "51663": "",
    "51664": "",
    "51669": "",
    "51670": "",
    "51671": "",
    "51672": "",
    "51673": "",
    "51674": "",
    "51675": "",
    "51708": "",
    "51733": ""
  },
  "source": "meta"
}