{
  "id": 501840,
  "title": "Method To Restore WEEK_NUM",
  "url": "/competitions/home-credit-credit-risk-model-stability/discussion/501840",
  "author_name": "KaiH",
  "post_date": "2024-05-11T00:04:22.817000",
  "votes": 9,
  "comment_count": 10,
  "views": 0,
  "content": "<p>So I don't know if this is known already but basically you just take refreshdate_3813885D max and subtract by 14 days and you get the dates back (a little bit of error, but pretty accurate with 0.91 correlation between actual and guessed). For the training dataset the weeks looped on day_of_week=1 so that's what I'm using but some experimentation will be needed. Also I have no idea what to do with WEEK_NUM so could anyone help.</p>\n<pre><code>testing = pd()()\ntesting = testing(, axis=)\n\ncreditA = ()\n\nmaxDates = (creditA\n()\n()\n()\n)()()()()\n\npredictDates = maxDates - pd(() + )\ntesting = pd(, axis=)()\n\ndateMin = testing()\ndateMax = testing()\nfirstMonday = testing()\n\ndayBetween = (dateMax - firstMonday)\ndayRange = \ntesting = \n\n   (-, (dayRange)):\n      &lt;  and testing() != firstMonday:\n        testing += ~testing()\n        continue\n\n\n    testing += testing &gt;= dayRange\n</code></pre>",
  "messages": [
    {
      "id": 2806179,
      "postDate": "2024-05-11T00:04:22.817Z",
      "content": "<p>So I don't know if this is known already but basically you just take refreshdate_3813885D max and subtract by 14 days and you get the dates back (a little bit of error, but pretty accurate with 0.91 correlation between actual and guessed). For the training dataset the weeks looped on day_of_week=1 so that's what I'm using but some experimentation will be needed. Also I have no idea what to do with WEEK_NUM so could anyone help.</p>\n<pre><code>testing = pd()()\ntesting = testing(, axis=)\n\ncreditA = ()\n\nmaxDates = (creditA\n()\n()\n()\n)()()()()\n\npredictDates = maxDates - pd(() + )\ntesting = pd(, axis=)()\n\ndateMin = testing()\ndateMax = testing()\nfirstMonday = testing()\n\ndayBetween = (dateMax - firstMonday)\ndayRange = \ntesting = \n\n   (-, (dayRange)):\n      &lt;  and testing() != firstMonday:\n        testing += ~testing()\n        continue\n\n\n    testing += testing &gt;= dayRange\n</code></pre>",
      "rawMarkdown": "So I don't know if this is known already but basically you just take refreshdate_3813885D max and subtract by 14 days and you get the dates back (a little bit of error, but pretty accurate with 0.91 correlation between actual and guessed). For the training dataset the weeks looped on day_of_week=1 so that's what I'm using but some experimentation will be needed. Also I have no idea what to do with WEEK_NUM so could anyone help.\n```\ntesting = pd.read_parquet(\"/kaggle/input/home-credit-credit-risk-model-stability/parquet_files/test/test_base.parquet\").set_index(\"case_id\")\ntesting = testing.drop(['date_decision', 'WEEK_NUM', 'MONTH'], axis=1)\n\ncreditA = readFiles(\"/kaggle/input/home-credit-credit-risk-model-stability/parquet_files/test/test_credit_bureau_a_1_*.parquet\")\n\nmaxDates = (creditA\n.select([pl.col(\"case_id\"), pl.col(\"refreshdate_3813885D\").str.to_datetime()])\n.group_by(\"case_id\")\n.max()\n).collect().to_pandas().set_index(\"case_id\").refreshdate_3813885D.sort_index()\n\npredictDates = maxDates - pd.to_timedelta(str(14) + \" days\")\ntesting = pd.concat([predictDates, testing], axis=1).sort_index()\n\ndateMin = testing.refreshdate_3813885D.min()\ndateMax = testing.refreshdate_3813885D.max()\nfirstMonday = testing.refreshdate_3813885D[testing.refreshdate_3813885D.dt.day_of_week==1].min()\n\ndayBetween = (dateMax - firstMonday).days\ndayRange = [firstMonday + pd.to_timedelta(str(i) + \" days\") for i in range(0, dayBetween, 7)]\ntesting[\"WEEK_NUM\"] = 0\n\nfor i in range(-1, len(dayRange)):\n    if i < 0 and testing.refreshdate_3813885D.min() != firstMonday:\n        testing[\"WEEK_NUM\"] += ~testing.refreshdate_3813885D.isna()\n        continue\n    \n    \n    testing[\"WEEK_NUM\"] += testing.refreshdate_3813885D >= dayRange[i]\n```",
      "votes": 9
    },
    {
      "id": 2806268,
      "postDate": "2024-05-11T02:14:20.237Z",
      "content": "<p>I see what you are doing. The max refreshdate is actually date_decision, so you use it to restore week_num. But I remember host have said date columns in test are transformed. So I am skeptical this would work.</p>",
      "rawMarkdown": "I see what you are doing. The max refreshdate is actually date_decision, so you use it to restore week_num. But I remember host have said date columns in test are transformed. So I am skeptical this would work.",
      "votes": 3,
      "replies": [
        {
          "id": 2808372,
          "postDate": "2024-05-12T06:54:16.813Z",
          "rawMarkdown": "",
          "isDeleted": true
        }
      ]
    },
    {
      "id": 2806197,
      "postDate": "2024-05-11T00:26:54.490Z",
      "content": "<p>Yeah, you can also use some other columns like recorddate and get similar results. Exploiting it is easy, just search public notebooks by “Metric trick”. </p>\n<p>The only question here is how all this is related to Kaggle mission and host’s goal. I personally kind of lost motivation, when heard host is not going to fix it.</p>",
      "rawMarkdown": "Yeah, you can also use some other columns like recorddate and get similar results. Exploiting it is easy, just search public notebooks by “Metric trick”. \n\nThe only question here is how all this is related to Kaggle mission and host’s goal. I personally kind of lost motivation, when heard host is not going to fix it.",
      "votes": 3
    },
    {
      "id": 2806635,
      "postDate": "2024-05-11T07:40:04.400Z",
      "content": "<p>I tried to restore WEEK_NUM by refreshdate_3813885D, but it didn't work in my public scores.</p>",
      "rawMarkdown": "I tried to restore WEEK_NUM by refreshdate_3813885D, but it didn't work in my public scores.",
      "replies": [
        {
          "id": 2806931,
          "postDate": "2024-05-11T12:03:21.690Z",
          "content": "<p>Oh interesting, I guess it just doesn't work. I thought I was using WEEK_NUM incorrectly.</p>",
          "rawMarkdown": "Oh interesting, I guess it just doesn't work. I thought I was using WEEK_NUM incorrectly.",
          "replies": [
            {
              "id": 2808283,
              "postDate": "2024-05-12T05:54:24.750Z",
              "content": "<p>Perhaps the order of the date column related to date decision has been rearranged, rendering their chronological sequence ineffective, thus preventing the restoration of the week</p>",
              "rawMarkdown": "Perhaps the order of the date column related to date decision has been rearranged, rendering their chronological sequence ineffective, thus preventing the restoration of the week"
            },
            {
              "id": 2817315,
              "postDate": "2024-05-16T20:17:17.387Z",
              "content": "<p>The host said some columns are transformed.<br>\n<a href=\"https://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/501853#2810448\" target=\"_blank\">https://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/501853#2810448</a></p>",
              "rawMarkdown": "The host said some columns are transformed.\nhttps://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/501853#2810448"
            }
          ]
        }
      ]
    },
    {
      "id": 2806240,
      "postDate": "2024-05-11T01:28:12.780Z",
      "content": "<p>I don't quite understand why we have to obtain WEEK_NUM through such a complex method.</p>\n<p>Is the WEEK_NUM in sample_submission.csv fake?</p>",
      "rawMarkdown": "I don't quite understand why we have to obtain WEEK_NUM through such a complex method.\n\n Is the WEEK_NUM in sample_submission.csv fake?",
      "votes": 1,
      "replies": [
        {
          "id": 2806259,
          "postDate": "2024-05-11T01:52:55.807Z",
          "content": "<p>If you mean test_base.csv yes it is. It is replaced by a constant.</p>",
          "rawMarkdown": "If you mean test_base.csv yes it is. It is replaced by a constant.",
          "votes": 1
        }
      ]
    },
    {
      "id": 2807127,
      "postDate": "2024-05-11T14:22:44.563Z",
      "rawMarkdown": "",
      "isDeleted": true
    }
  ],
  "comments": [
    {
      "id": 2806268,
      "author_name": "Evan",
      "author_url": "",
      "post_date": "2024-05-11T02:14:20.237000",
      "content": "<p>I see what you are doing. The max refreshdate is actually date_decision, so you use it to restore week_num. But I remember host have said date columns in test are transformed. So I am skeptical this would work.</p>",
      "votes": 3,
      "replies": [
        {
          "id": 2808372,
          "author_name": "",
          "author_url": "",
          "post_date": "2024-05-12T06:54:16.813000",
          "content": "",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2806197,
      "author_name": "Oleksiy Kononenko",
      "author_url": "",
      "post_date": "2024-05-11T00:26:54.490000",
      "content": "<p>Yeah, you can also use some other columns like recorddate and get similar results. Exploiting it is easy, just search public notebooks by “Metric trick”. </p>\n<p>The only question here is how all this is related to Kaggle mission and host’s goal. I personally kind of lost motivation, when heard host is not going to fix it.</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 2806635,
      "author_name": "LX",
      "author_url": "",
      "post_date": "2024-05-11T07:40:04.400000",
      "content": "<p>I tried to restore WEEK_NUM by refreshdate_3813885D, but it didn't work in my public scores.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 2806931,
          "author_name": "KaiH",
          "author_url": "",
          "post_date": "2024-05-11T12:03:21.690000",
          "content": "<p>Oh interesting, I guess it just doesn't work. I thought I was using WEEK_NUM incorrectly.</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2808283,
              "author_name": "LX",
              "author_url": "",
              "post_date": "2024-05-12T05:54:24.750000",
              "content": "<p>Perhaps the order of the date column related to date decision has been rearranged, rendering their chronological sequence ineffective, thus preventing the restoration of the week</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 2817315,
              "author_name": "ano",
              "author_url": "",
              "post_date": "2024-05-16T20:17:17.387000",
              "content": "<p>The host said some columns are transformed.<br>\n<a href=\"https://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/501853#2810448\" target=\"_blank\">https://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/501853#2810448</a></p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2806240,
      "author_name": "Bruce",
      "author_url": "",
      "post_date": "2024-05-11T01:28:12.780000",
      "content": "<p>I don't quite understand why we have to obtain WEEK_NUM through such a complex method.</p>\n<p>Is the WEEK_NUM in sample_submission.csv fake?</p>",
      "votes": 1,
      "replies": [
        {
          "id": 2806259,
          "author_name": "KaiH",
          "author_url": "",
          "post_date": "2024-05-11T01:52:55.807000",
          "content": "<p>If you mean test_base.csv yes it is. It is replaced by a constant.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 2807127,
      "author_name": "",
      "author_url": "",
      "post_date": "2024-05-11T14:22:44.563000",
      "content": "",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2806179": "So I don't know if this is known already but basically you just take refreshdate_3813885D max and subtract by 14 days and you get the dates back (a little bit of error, but pretty accurate with 0.91 correlation between actual and guessed). For the training dataset the weeks looped on day_of_week=1 so that's what I'm using but some experimentation will be needed. Also I have no idea what to do with WEEK_NUM so could anyone help.\n```\ntesting = pd.read_parquet(\"/kaggle/input/home-credit-credit-risk-model-stability/parquet_files/test/test_base.parquet\").set_index(\"case_id\")\ntesting = testing.drop(['date_decision', 'WEEK_NUM', 'MONTH'], axis=1)\n\ncreditA = readFiles(\"/kaggle/input/home-credit-credit-risk-model-stability/parquet_files/test/test_credit_bureau_a_1_*.parquet\")\n\nmaxDates = (creditA\n.select([pl.col(\"case_id\"), pl.col(\"refreshdate_3813885D\").str.to_datetime()])\n.group_by(\"case_id\")\n.max()\n).collect().to_pandas().set_index(\"case_id\").refreshdate_3813885D.sort_index()\n\npredictDates = maxDates - pd.to_timedelta(str(14) + \" days\")\ntesting = pd.concat([predictDates, testing], axis=1).sort_index()\n\ndateMin = testing.refreshdate_3813885D.min()\ndateMax = testing.refreshdate_3813885D.max()\nfirstMonday = testing.refreshdate_3813885D[testing.refreshdate_3813885D.dt.day_of_week==1].min()\n\ndayBetween = (dateMax - firstMonday).days\ndayRange = [firstMonday + pd.to_timedelta(str(i) + \" days\") for i in range(0, dayBetween, 7)]\ntesting[\"WEEK_NUM\"] = 0\n\nfor i in range(-1, len(dayRange)):\n    if i < 0 and testing.refreshdate_3813885D.min() != firstMonday:\n        testing[\"WEEK_NUM\"] += ~testing.refreshdate_3813885D.isna()\n        continue\n    \n    \n    testing[\"WEEK_NUM\"] += testing.refreshdate_3813885D >= dayRange[i]\n```",
    "2806268": "I see what you are doing. The max refreshdate is actually date_decision, so you use it to restore week_num. But I remember host have said date columns in test are transformed. So I am skeptical this would work.",
    "2806197": "Yeah, you can also use some other columns like recorddate and get similar results. Exploiting it is easy, just search public notebooks by “Metric trick”. \n\nThe only question here is how all this is related to Kaggle mission and host’s goal. I personally kind of lost motivation, when heard host is not going to fix it.",
    "2806635": "I tried to restore WEEK_NUM by refreshdate_3813885D, but it didn't work in my public scores.",
    "2806240": "I don't quite understand why we have to obtain WEEK_NUM through such a complex method.\n\n Is the WEEK_NUM in sample_submission.csv fake?",
    "2807127": ""
  }
}