{
  "id": 200636,
  "title": "Be careful when groupby task_container_id or timestamp",
  "url": "/competitions/riiid-test-answer-prediction/discussion/200636",
  "author_name": "",
  "post_date": "2020-12-01T08:42:32.255431100Z",
  "votes": 8,
  "comment_count": 11,
  "views": 0,
  "content": "<p>I found some logical bugs in my code.<br>\nIt comes from <br>\n<code>data.groupby(['user_id', 'task_container_id'])</code> <br>\n<code>data.groupby(['user_id', 'timestamp '])</code></p>\n<p>I think the reason is </p>\n<ol>\n<li>task_container_id is not monotonically increasing for each user as <a href=\"https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189513\" target=\"_blank\">this topic describes</a></li>\n<li>some tasks share the same timestamp </li>\n</ol>\n<p>for example</p>\n<table>\n<thead>\n<tr>\n<th>timestamp</th>\n<th>user_id</th>\n<th>task_container_id</th>\n<th>answered_correctly</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>166938177</td>\n<td>712889458</td>\n<td>57</td>\n<td>1</td>\n</tr>\n<tr>\n<td>167006365</td>\n<td>712889458</td>\n<td>59</td>\n<td>1</td>\n</tr>\n<tr>\n<td>167006365</td>\n<td>712889458</td>\n<td>58</td>\n<td>0</td>\n</tr>\n<tr>\n<td>167006365</td>\n<td>712889458</td>\n<td>60</td>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n<p>It puzzled me until I find <a href=\"https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189465\" target=\"_blank\">this topic</a><br>\nIf it's new to you, hope you get some tips from here</p>",
  "messages": [
    {
      "id": "1097788",
      "postDate": "12/01/2020 08:42:32",
      "content": "<p>I found some logical bugs in my code.<br>\nIt comes from <br>\n<code>data.groupby(['user_id', 'task_container_id'])</code> <br>\n<code>data.groupby(['user_id', 'timestamp '])</code></p>\n<p>I think the reason is </p>\n<ol>\n<li>task_container_id is not monotonically increasing for each user as <a href=\"https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189513\" target=\"_blank\">this topic describes</a></li>\n<li>some tasks share the same timestamp </li>\n</ol>\n<p>for example</p>\n<table>\n<thead>\n<tr>\n<th>timestamp</th>\n<th>user_id</th>\n<th>task_container_id</th>\n<th>answered_correctly</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>166938177</td>\n<td>712889458</td>\n<td>57</td>\n<td>1</td>\n</tr>\n<tr>\n<td>167006365</td>\n<td>712889458</td>\n<td>59</td>\n<td>1</td>\n</tr>\n<tr>\n<td>167006365</td>\n<td>712889458</td>\n<td>58</td>\n<td>0</td>\n</tr>\n<tr>\n<td>167006365</td>\n<td>712889458</td>\n<td>60</td>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n<p>It puzzled me until I find <a href=\"https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189465\" target=\"_blank\">this topic</a><br>\nIf it's new to you, hope you get some tips from here</p>",
      "rawMarkdown": "I found some logical bugs in my code.\nIt comes from \n`data.groupby(['user_id', 'task_container_id'])` \n`data.groupby(['user_id', 'timestamp '])`\n\nI think the reason is \n1. task_container_id is not monotonically increasing for each user as [this topic describes](https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189513)\n2. some tasks share the same timestamp \n\nfor example\n| timestamp | user_id | task_container_id | answered_correctly\n| --- | --- |\n|  166938177|  712889458|57 | 1\n|  167006365|  712889458|59| 1\n|  167006365|  712889458|58| 0\n|  167006365|  712889458|60| 1\n\nIt puzzled me until I find [this topic](https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189465)\nIf it's new to you, hope you get some tips from here",
      "votes": null
    },
    {
      "id": "1098979",
      "postDate": "12/02/2020 01:57:50",
      "content": "<p>Why is the timestamp the same but the task_container_id is different?<br>\nIn my opinion, if the timestamp is the same, the questions are served together and task_container_id will be the same.</p>",
      "rawMarkdown": "Why is the timestamp the same but the task_container_id is different?\nIn my opinion, if the timestamp is the same, the questions are served together and task_container_id will be the same.",
      "votes": null
    },
    {
      "id": "1099087",
      "postDate": "12/02/2020 04:37:47",
      "content": "<blockquote>\n  <p>The timestamp column shows when an activity is finished, not when it started. A user could have spent an arbitrary amount of time working on the first problem before the first timestamp value would get logged.</p>\n</blockquote>\n<p><a href=\"https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189465\" target=\"_blank\">more details</a></p>",
      "rawMarkdown": "> The timestamp column shows when an activity is finished, not when it started. A user could have spent an arbitrary amount of time working on the first problem before the first timestamp value would get logged.\n\n[more details](https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189465)",
      "votes": null
    },
    {
      "id": "1099138",
      "postDate": "12/02/2020 05:38:08",
      "content": "<p>Simply add <code>sort=False</code> in groupby function and it should work fine.</p>",
      "rawMarkdown": "Simply add `sort=False` in groupby function and it should work fine.",
      "votes": null
    },
    {
      "id": "1099226",
      "postDate": "12/02/2020 07:33:34",
      "content": "<p>You're right, dude<br>\nBut I did not know these timestap and task_container_id information before</p>",
      "rawMarkdown": "You're right, dude\nBut I did not know these timestap and task_container_id information before",
      "votes": null
    },
    {
      "id": "1100373",
      "postDate": "12/03/2020 03:37:05",
      "content": "<p>Hi Solomon, Sorry for the n00b question. <br>\nHow is this a logical bug? It looks like consistently use task_container_id or timestamp should be fine.<br>\nAlso, based on my understanding, add <code>sort=False</code> in groupby function will just make the result unsorted, what's the special need here?<br>\nAppreciate any educating here</p>",
      "rawMarkdown": "Hi Solomon, Sorry for the n00b question. \nHow is this a logical bug? It looks like consistently use task_container_id or timestamp should be fine.\nAlso, based on my understanding, add `sort=False` in groupby function will just make the result unsorted, what's the special need here?\nAppreciate any educating here",
      "votes": null
    },
    {
      "id": "1100419",
      "postDate": "12/03/2020 04:40:49",
      "content": "<p>Because I did not know </p>\n<ol>\n<li>task_container_id is not monotonically increasing for each user</li>\n<li>timestamp is not monotonically increasing for each user</li>\n</ol>\n<p>I created features base on them which I thought were in order, <br>\nand of cause I did not recive error or warning.<br>\nIt means I need to find these bugs by myself. (Even more, I need to realise it at first)<br>\nYou may call it \"careless bug\"😃</p>",
      "rawMarkdown": "Because I did not know \n1. task_container_id is not monotonically increasing for each user\n2. timestamp is not monotonically increasing for each user\n\nI created features base on them which I thought were in order, \nand of cause I did not recive error or warning.\nIt means I need to find these bugs by myself. (Even more, I need to realise it at first)\nYou may call it \"careless bug\"😃",
      "votes": null
    },
    {
      "id": "1100433",
      "postDate": "12/03/2020 04:56:02",
      "content": "<p>Thank you for the quick reply. I see, so your feature rely on the order and it's more like a logic bug?<br>\nAlso, as I learned from description of API, </p>\n<blockquote>\n  <p>Each group will contain interactions from many different users, but no more than one task_container_id of questions from any single user. </p>\n</blockquote>\n<p>which means during testing phase in each group, each user will only have 1 single task_container_id. Do I understand correctly?</p>",
      "rawMarkdown": "Thank you for the quick reply. I see, so your feature rely on the order and it's more like a logic bug?\nAlso, as I learned from description of API, \n> Each group will contain interactions from many different users, but no more than one task_container_id of questions from any single user. \n\nwhich means during testing phase in each group, each user will only have 1 single task_container_id. Do I understand correctly?",
      "votes": null
    },
    {
      "id": "1100458",
      "postDate": "12/03/2020 05:13:13",
      "content": "<p>You're right <br>\nJust remember timestamp is the finish time, and task id is not totally in order</p>",
      "rawMarkdown": "You're right \nJust remember timestamp is the finish time, and task id is not totally in order",
      "votes": null
    },
    {
      "id": "1100476",
      "postDate": "12/03/2020 05:31:09",
      "content": "<p>This are the only tuples that have repeated task_id I do not think it is much of a problem<br>\nuser_id    timestamp  <br>\n7171715    6828386        2<br>\n37317993   1729136465     2<br>\n169835132  16435464437    2<br>\n575358140  2136919285     2<br>\n712889458  167006365      2<br>\n743195685  2014787948     2<br>\n828365782  6067874053     2<br>\n857524087  11647087       2<br>\n917426026  170401915      2<br>\n993524405  1351161810     2</p>\n<p>But part 1 is surely strange.</p>",
      "rawMarkdown": "This are the only tuples that have repeated task_id I do not think it is much of a problem\nuser_id    timestamp  \n7171715    6828386        2\n37317993   1729136465     2\n169835132  16435464437    2\n575358140  2136919285     2\n712889458  167006365      2\n743195685  2014787948     2\n828365782  6067874053     2\n857524087  11647087       2\n917426026  170401915      2\n993524405  1351161810     2\n\nBut part 1 is surely strange.",
      "votes": null
    },
    {
      "id": "1101730",
      "postDate": "12/04/2020 07:20:16",
      "content": "<p>Can a user run two or more sessions simultaneously?</p>",
      "rawMarkdown": "Can a user run two or more sessions simultaneously?",
      "votes": null
    },
    {
      "id": "1101765",
      "postDate": "12/04/2020 08:14:37",
      "content": "<p>It seems Yes.<br>\nIn my opinion, task id shows the start order, and timestamp shows the finish order</p>",
      "rawMarkdown": "It seems Yes.\nIn my opinion, task id shows the start order, and timestamp shows the finish order",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1098979,
      "author_name": "m10515009",
      "author_url": "",
      "post_date": "12/02/2020 01:57:50",
      "content": "<p>Why is the timestamp the same but the task_container_id is different?<br>\nIn my opinion, if the timestamp is the same, the questions are served together and task_container_id will be the same.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1099087,
          "author_name": "solomonxian",
          "author_url": "",
          "post_date": "12/02/2020 04:37:47",
          "content": "<blockquote>\n  <p>The timestamp column shows when an activity is finished, not when it started. A user could have spent an arbitrary amount of time working on the first problem before the first timestamp value would get logged.</p>\n</blockquote>\n<p><a href=\"https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189465\" target=\"_blank\">more details</a></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1101730,
          "author_name": "neustroev",
          "author_url": "",
          "post_date": "12/04/2020 07:20:16",
          "content": "<p>Can a user run two or more sessions simultaneously?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1101765,
          "author_name": "solomonxian",
          "author_url": "",
          "post_date": "12/04/2020 08:14:37",
          "content": "<p>It seems Yes.<br>\nIn my opinion, task id shows the start order, and timestamp shows the finish order</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1099138,
      "author_name": "dexarsal",
      "author_url": "",
      "post_date": "12/02/2020 05:38:08",
      "content": "<p>Simply add <code>sort=False</code> in groupby function and it should work fine.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1099226,
          "author_name": "solomonxian",
          "author_url": "",
          "post_date": "12/02/2020 07:33:34",
          "content": "<p>You're right, dude<br>\nBut I did not know these timestap and task_container_id information before</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1100373,
      "author_name": "creatrol",
      "author_url": "",
      "post_date": "12/03/2020 03:37:05",
      "content": "<p>Hi Solomon, Sorry for the n00b question. <br>\nHow is this a logical bug? It looks like consistently use task_container_id or timestamp should be fine.<br>\nAlso, based on my understanding, add <code>sort=False</code> in groupby function will just make the result unsorted, what's the special need here?<br>\nAppreciate any educating here</p>",
      "votes": null,
      "replies": [
        {
          "id": 1100419,
          "author_name": "solomonxian",
          "author_url": "",
          "post_date": "12/03/2020 04:40:49",
          "content": "<p>Because I did not know </p>\n<ol>\n<li>task_container_id is not monotonically increasing for each user</li>\n<li>timestamp is not monotonically increasing for each user</li>\n</ol>\n<p>I created features base on them which I thought were in order, <br>\nand of cause I did not recive error or warning.<br>\nIt means I need to find these bugs by myself. (Even more, I need to realise it at first)<br>\nYou may call it \"careless bug\"😃</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1100433,
          "author_name": "creatrol",
          "author_url": "",
          "post_date": "12/03/2020 04:56:02",
          "content": "<p>Thank you for the quick reply. I see, so your feature rely on the order and it's more like a logic bug?<br>\nAlso, as I learned from description of API, </p>\n<blockquote>\n  <p>Each group will contain interactions from many different users, but no more than one task_container_id of questions from any single user. </p>\n</blockquote>\n<p>which means during testing phase in each group, each user will only have 1 single task_container_id. Do I understand correctly?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1100458,
          "author_name": "solomonxian",
          "author_url": "",
          "post_date": "12/03/2020 05:13:13",
          "content": "<p>You're right <br>\nJust remember timestamp is the finish time, and task id is not totally in order</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1100476,
      "author_name": "felipebihaiek",
      "author_url": "",
      "post_date": "12/03/2020 05:31:09",
      "content": "<p>This are the only tuples that have repeated task_id I do not think it is much of a problem<br>\nuser_id    timestamp  <br>\n7171715    6828386        2<br>\n37317993   1729136465     2<br>\n169835132  16435464437    2<br>\n575358140  2136919285     2<br>\n712889458  167006365      2<br>\n743195685  2014787948     2<br>\n828365782  6067874053     2<br>\n857524087  11647087       2<br>\n917426026  170401915      2<br>\n993524405  1351161810     2</p>\n<p>But part 1 is surely strange.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1097788": "I found some logical bugs in my code.\nIt comes from \n`data.groupby(['user_id', 'task_container_id'])` \n`data.groupby(['user_id', 'timestamp '])`\n\nI think the reason is \n1. task_container_id is not monotonically increasing for each user as [this topic describes](https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189513)\n2. some tasks share the same timestamp \n\nfor example\n| timestamp | user_id | task_container_id | answered_correctly\n| --- | --- |\n|  166938177|  712889458|57 | 1\n|  167006365|  712889458|59| 1\n|  167006365|  712889458|58| 0\n|  167006365|  712889458|60| 1\n\nIt puzzled me until I find [this topic](https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189465)\nIf it's new to you, hope you get some tips from here",
    "1098979": "Why is the timestamp the same but the task_container_id is different?\nIn my opinion, if the timestamp is the same, the questions are served together and task_container_id will be the same.",
    "1099087": "> The timestamp column shows when an activity is finished, not when it started. A user could have spent an arbitrary amount of time working on the first problem before the first timestamp value would get logged.\n\n[more details](https://www.kaggle.com/c/riiid-test-answer-prediction/discussion/189465)",
    "1099138": "Simply add `sort=False` in groupby function and it should work fine.",
    "1099226": "You're right, dude\nBut I did not know these timestap and task_container_id information before",
    "1100373": "Hi Solomon, Sorry for the n00b question. \nHow is this a logical bug? It looks like consistently use task_container_id or timestamp should be fine.\nAlso, based on my understanding, add `sort=False` in groupby function will just make the result unsorted, what's the special need here?\nAppreciate any educating here",
    "1100419": "Because I did not know \n1. task_container_id is not monotonically increasing for each user\n2. timestamp is not monotonically increasing for each user\n\nI created features base on them which I thought were in order, \nand of cause I did not recive error or warning.\nIt means I need to find these bugs by myself. (Even more, I need to realise it at first)\nYou may call it \"careless bug\"😃",
    "1100433": "Thank you for the quick reply. I see, so your feature rely on the order and it's more like a logic bug?\nAlso, as I learned from description of API, \n> Each group will contain interactions from many different users, but no more than one task_container_id of questions from any single user. \n\nwhich means during testing phase in each group, each user will only have 1 single task_container_id. Do I understand correctly?",
    "1100458": "You're right \nJust remember timestamp is the finish time, and task id is not totally in order",
    "1100476": "This are the only tuples that have repeated task_id I do not think it is much of a problem\nuser_id    timestamp  \n7171715    6828386        2\n37317993   1729136465     2\n169835132  16435464437    2\n575358140  2136919285     2\n712889458  167006365      2\n743195685  2014787948     2\n828365782  6067874053     2\n857524087  11647087       2\n917426026  170401915      2\n993524405  1351161810     2\n\nBut part 1 is surely strange.",
    "1101730": "Can a user run two or more sessions simultaneously?",
    "1101765": "It seems Yes.\nIn my opinion, task id shows the start order, and timestamp shows the finish order"
  },
  "source": "meta"
}