{
  "id": 411395,
  "title": "8th place solution: One trick to win the gold",
  "content": "<p>Thanks my teammates <a href=\"https://www.kaggle.com/hookman\" target=\"_blank\">@hookman</a> <a href=\"https://www.kaggle.com/zui0711\" target=\"_blank\">@zui0711</a> <a href=\"https://www.kaggle.com/max2020\" target=\"_blank\">@max2020</a> <a href=\"https://www.kaggle.com/librauee\" target=\"_blank\">@librauee</a> , I have learnt a lot from them. A crucial trick found by them is there are two groups in the data: <strong>The true patients and the control group</strong>. We can find this by <strong>the minimum visit_month diff</strong> of each id:</p>\n<pre><code>for df in [clinical, sup_clinical]:\n    df['visit_month_diff'] = df.groupby(['patient_id'])['visit_month'].diff()\n    df['visit_month_diff_min'] = df.groupby('patient_id')['visit_month_diff'].transform('min')\n</code></pre>\n<p>There are 3, 5, 6, 12, 36 visit_month diff in clinical and sup_clinical, we choose only 3, 6, 12, 36 parts as training data, and transform 3, 36 to 6. We find 3, 6 and 36 has obviously higher updrs values and 12 has lower updrs values(5 part dropped as abnormal).<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3110858%2F99690a48cfd9b72ad8bc4fc746815856%2FWX20230519-0926512x.png?generation=1684460243462016&amp;alt=media\" alt=\"updrs in different visit_month diff and months\"><br>\nWe can draw a conclusion <strong>visit_month diff==6</strong> are true patients and <strong>visit_month diff==12</strong> are control group.<br>\nWe use piecewise function to optimize two groups smape separately:</p>\n<pre><code>def calculate_predictions(pred_month, trend):\n    if target == 'updrs_4': \n        pred_month = pred_month.clip(60, None) \n    pred_month2 = (pred_month-60).clip(0, None)\n    return np.round(trend[0] + pred_month * trend[1] + pred_month2 * trend[2])\n</code></pre>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3110858%2F5705a4149bab70f274bd16c521c5c967%2FWX20230519-1027572x.png?generation=1684463307465921&amp;alt=media\" alt=\"0=control group, 1=true patients\"><br>\nIn the first loop inference, we cannot get visit_month diff, so we train additional coefficients based on true patients + control group. In every loop, we record history data so that we could get the <strong>the minimum visit_month diff</strong>.<br>\nFinding these two groups can help you reach 54.2~54.8 on public board and 60.1~60.7 on private board.</p>",
  "comments": [],
  "comment_count": 0,
  "messages": [
    {
      "id": 2265120,
      "postDate": "2023-05-19T02:03:15.737Z",
      "content": "<p>Thanks my teammates <a href=\"https://www.kaggle.com/hookman\" target=\"_blank\">@hookman</a> <a href=\"https://www.kaggle.com/zui0711\" target=\"_blank\">@zui0711</a> <a href=\"https://www.kaggle.com/max2020\" target=\"_blank\">@max2020</a> <a href=\"https://www.kaggle.com/librauee\" target=\"_blank\">@librauee</a> , I have learnt a lot from them. A crucial trick found by them is there are two groups in the data: <strong>The true patients and the control group</strong>. We can find this by <strong>the minimum visit_month diff</strong> of each id:</p>\n<pre><code>for df in [clinical, sup_clinical]:\n    df['visit_month_diff'] = df.groupby(['patient_id'])['visit_month'].diff()\n    df['visit_month_diff_min'] = df.groupby('patient_id')['visit_month_diff'].transform('min')\n</code></pre>\n<p>There are 3, 5, 6, 12, 36 visit_month diff in clinical and sup_clinical, we choose only 3, 6, 12, 36 parts as training data, and transform 3, 36 to 6. We find 3, 6 and 36 has obviously higher updrs values and 12 has lower updrs values(5 part dropped as abnormal).<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3110858%2F99690a48cfd9b72ad8bc4fc746815856%2FWX20230519-0926512x.png?generation=1684460243462016&amp;alt=media\" alt=\"updrs in different visit_month diff and months\"><br>\nWe can draw a conclusion <strong>visit_month diff==6</strong> are true patients and <strong>visit_month diff==12</strong> are control group.<br>\nWe use piecewise function to optimize two groups smape separately:</p>\n<pre><code>def calculate_predictions(pred_month, trend):\n    if target == 'updrs_4': \n        pred_month = pred_month.clip(60, None) \n    pred_month2 = (pred_month-60).clip(0, None)\n    return np.round(trend[0] + pred_month * trend[1] + pred_month2 * trend[2])\n</code></pre>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3110858%2F5705a4149bab70f274bd16c521c5c967%2FWX20230519-1027572x.png?generation=1684463307465921&amp;alt=media\" alt=\"0=control group, 1=true patients\"><br>\nIn the first loop inference, we cannot get visit_month diff, so we train additional coefficients based on true patients + control group. In every loop, we record history data so that we could get the <strong>the minimum visit_month diff</strong>.<br>\nFinding these two groups can help you reach 54.2~54.8 on public board and 60.1~60.7 on private board.</p>",
      "rawMarkdown": "Thanks my teammates @hookman @zui0711 @max2020 @librauee , I have learnt a lot from them. A crucial trick found by them is there are two groups in the data: **The true patients and the control group**. We can find this by **the minimum visit_month diff** of each id:\n```\nfor df in [clinical, sup_clinical]:\n    df['visit_month_diff'] = df.groupby(['patient_id'])['visit_month'].diff()\n    df['visit_month_diff_min'] = df.groupby('patient_id')['visit_month_diff'].transform('min')\n```\nThere are 3, 5, 6, 12, 36 visit_month diff in clinical and sup_clinical, we choose only 3, 6, 12, 36 parts as training data, and transform 3, 36 to 6. We find 3, 6 and 36 has obviously higher updrs values and 12 has lower updrs values(5 part dropped as abnormal).\n![updrs in different visit_month diff and months](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3110858%2F99690a48cfd9b72ad8bc4fc746815856%2FWX20230519-0926512x.png?generation=1684460243462016&alt=media)\nWe can draw a conclusion **visit_month diff==6** are true patients and **visit_month diff==12** are control group.\nWe use piecewise function to optimize two groups smape separately:\n```\ndef calculate_predictions(pred_month, trend):\n    if target == 'updrs_4': \n        pred_month = pred_month.clip(60, None) \n    pred_month2 = (pred_month-60).clip(0, None)\n    return np.round(trend[0] + pred_month * trend[1] + pred_month2 * trend[2])\n```\n![0=control group, 1=true patients](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3110858%2F5705a4149bab70f274bd16c521c5c967%2FWX20230519-1027572x.png?generation=1684463307465921&alt=media)\nIn the first loop inference, we cannot get visit_month diff, so we train additional coefficients based on true patients + control group. In every loop, we record history data so that we could get the **the minimum visit_month diff**.\nFinding these two groups can help you reach 54.2~54.8 on public board and 60.1~60.7 on private board.",
      "votes": 28
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-19T14:12:03Z",
  "competition_id": 37794,
  "competition_slug": "amp-parkinsons-disease-progression-prediction",
  "team_id": 9913452,
  "solution_url": "/competitions/amp-parkinsons-disease-progression-prediction/writeups/all-luck-no-skill-8th-place-solution-one-trick-to-"
}