{
  "id": 341103,
  "title": "Summary of 1st place solution",
  "url": "/competitions/energy-anomaly-detection/writeups/chun-fu-summary-of-1st-place-solution",
  "author_name": "",
  "post_date": "2022-08-01T08:13:04.789157300Z",
  "votes": 12,
  "comment_count": 3,
  "views": 0,
  "content": "<p>Special thanks to the competition host <a href=\"https://www.kaggle.com/samy101\" target=\"_blank\">@samy101</a> !</p>\n<p>This is indeed a small but interesting competition for detecting time-series anomalies. Although I've included various common techiniques and some of them could help improve the score, the feature engineering dominates among all, especially change-of-value features with varying shift steps have significantly positive impact. With only 200 labeled time series for training, the resultant 0.9866 of ROC-AUC score on unseen 206 time series also surprises me. Tree-based model is indeed a beast for regression and classification task : D</p>\n<p>My winning solution is briefly summarized as follows, and the complete script will be soon released to the public in weeks:</p>\n<p><strong>1. Data preprocessing</strong></p>\n<ul>\n<li>No anomalies were removed because the goal of this contest is anomaly detection</li>\n<li>Missing values (NaN) were replaced with the median value of each time series</li>\n</ul>\n<p><strong>2. Feature enegineering</strong></p>\n<ul>\n<li>Building meta data and weather data</li>\n<li>Temporal features (e.g., hour, weekday, and day of year)</li>\n<li>Target encoding features (ref: preprocessing script from 1st place team in GEPIII)[<a href=\"https://lnkd.in/gdnxRUvz\" target=\"_blank\">https://lnkd.in/gdnxRUvz</a>]</li>\n<li>Change-of-value features: calculate change of value compared to nearby values (e.g., X(t)-X(t-1) and X(t)/X(t-1)) with varying shift steps (from 1 hour to 168 hours))</li>\n<li>Features from data smoothing and k-means clustering were also tried, but they don’t appear to significantly improve the score</li>\n</ul>\n<p><strong>3. Modeling</strong></p>\n<ul>\n<li>Train/valid split by building_id to ensure the valid data were unseen during training</li>\n<li>Downsampling training dataset to solve data imbalance (~5% of anomalies): normal values : abnormal values = 1:1</li>\n<li>Model ensembling via simple averaging: XGBosst, LightGBM, CatBoost, and HistGradientBoosting (weight of 0.25 for each)</li>\n</ul>\n<p><strong>4. Postprocessing</strong></p>\n<ul>\n<li>Set zeros to rows with 1.0 of meter_reading</li>\n<li>Set zeros to start and end points of time series</li>\n</ul>\n<p>Hope this can help : )</p>",
  "messages": [
    {
      "id": "1879729",
      "postDate": "08/01/2022 08:13:04",
      "content": "<p>Special thanks to the competition host <a href=\"https://www.kaggle.com/samy101\" target=\"_blank\">@samy101</a> !</p>\n<p>This is indeed a small but interesting competition for detecting time-series anomalies. Although I've included various common techiniques and some of them could help improve the score, the feature engineering dominates among all, especially change-of-value features with varying shift steps have significantly positive impact. With only 200 labeled time series for training, the resultant 0.9866 of ROC-AUC score on unseen 206 time series also surprises me. Tree-based model is indeed a beast for regression and classification task : D</p>\n<p>My winning solution is briefly summarized as follows, and the complete script will be soon released to the public in weeks:</p>\n<p><strong>1. Data preprocessing</strong></p>\n<ul>\n<li>No anomalies were removed because the goal of this contest is anomaly detection</li>\n<li>Missing values (NaN) were replaced with the median value of each time series</li>\n</ul>\n<p><strong>2. Feature enegineering</strong></p>\n<ul>\n<li>Building meta data and weather data</li>\n<li>Temporal features (e.g., hour, weekday, and day of year)</li>\n<li>Target encoding features (ref: preprocessing script from 1st place team in GEPIII)[<a href=\"https://lnkd.in/gdnxRUvz\" target=\"_blank\">https://lnkd.in/gdnxRUvz</a>]</li>\n<li>Change-of-value features: calculate change of value compared to nearby values (e.g., X(t)-X(t-1) and X(t)/X(t-1)) with varying shift steps (from 1 hour to 168 hours))</li>\n<li>Features from data smoothing and k-means clustering were also tried, but they don’t appear to significantly improve the score</li>\n</ul>\n<p><strong>3. Modeling</strong></p>\n<ul>\n<li>Train/valid split by building_id to ensure the valid data were unseen during training</li>\n<li>Downsampling training dataset to solve data imbalance (~5% of anomalies): normal values : abnormal values = 1:1</li>\n<li>Model ensembling via simple averaging: XGBosst, LightGBM, CatBoost, and HistGradientBoosting (weight of 0.25 for each)</li>\n</ul>\n<p><strong>4. Postprocessing</strong></p>\n<ul>\n<li>Set zeros to rows with 1.0 of meter_reading</li>\n<li>Set zeros to start and end points of time series</li>\n</ul>\n<p>Hope this can help : )</p>",
      "rawMarkdown": "Special thanks to the competition host @samy101 !\n\nThis is indeed a small but interesting competition for detecting time-series anomalies. Although I've included various common techiniques and some of them could help improve the score, the feature engineering dominates among all, especially change-of-value features with varying shift steps have significantly positive impact. With only 200 labeled time series for training, the resultant 0.9866 of ROC-AUC score on unseen 206 time series also surprises me. Tree-based model is indeed a beast for regression and classification task : D\n\nMy winning solution is briefly summarized as follows, and the complete script will be soon released to the public in weeks:\n\n**1. Data preprocessing**\n- No anomalies were removed because the goal of this contest is anomaly detection\n- Missing values (NaN) were replaced with the median value of each time series\n\n**2. Feature enegineering**\n- Building meta data and weather data\n- Temporal features (e.g., hour, weekday, and day of year)\n- Target encoding features (ref: preprocessing script from 1st place team in GEPIII)[https://lnkd.in/gdnxRUvz]\n- Change-of-value features: calculate change of value compared to nearby values (e.g., X(t)-X(t-1) and X(t)/X(t-1)) with varying shift steps (from 1 hour to 168 hours))\n- Features from data smoothing and k-means clustering were also tried, but they don’t appear to significantly improve the score\n\n**3. Modeling**\n- Train/valid split by building_id to ensure the valid data were unseen during training\n- Downsampling training dataset to solve data imbalance (~5% of anomalies): normal values : abnormal values = 1:1\n- Model ensembling via simple averaging: XGBosst, LightGBM, CatBoost, and HistGradientBoosting (weight of 0.25 for each)\n\n**4. Postprocessing**\n- Set zeros to rows with 1.0 of meter_reading\n- Set zeros to start and end points of time series\n\nHope this can help : )",
      "votes": null
    },
    {
      "id": "1882385",
      "postDate": "08/03/2022 08:46:47",
      "content": "<p>Yes, this is helpful. Congratulations for your position! Thanks for the summary!</p>",
      "rawMarkdown": "Yes, this is helpful. Congratulations for your position! Thanks for the summary!",
      "votes": null
    },
    {
      "id": "1882413",
      "postDate": "08/03/2022 09:07:31",
      "content": "<p>Thanks and that's my pleasure : )</p>",
      "rawMarkdown": "Thanks and that's my pleasure : )",
      "votes": null
    },
    {
      "id": "1888794",
      "postDate": "08/07/2022 19:25:03",
      "content": "<p>Congratulations on your win! This is a great summary of your solution and will be very helpful for others looking to learn from your approach. </p>\n<p>The Devastator.</p>",
      "rawMarkdown": "Congratulations on your win! This is a great summary of your solution and will be very helpful for others looking to learn from your approach. \n\nThe Devastator.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1882385,
      "author_name": "ravi20076",
      "author_url": "",
      "post_date": "08/03/2022 08:46:47",
      "content": "<p>Yes, this is helpful. Congratulations for your position! Thanks for the summary!</p>",
      "votes": null,
      "replies": [
        {
          "id": 1882413,
          "author_name": "patrick0302",
          "author_url": "",
          "post_date": "08/03/2022 09:07:31",
          "content": "<p>Thanks and that's my pleasure : )</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1888794,
      "author_name": "thedevastator",
      "author_url": "",
      "post_date": "08/07/2022 19:25:03",
      "content": "<p>Congratulations on your win! This is a great summary of your solution and will be very helpful for others looking to learn from your approach. </p>\n<p>The Devastator.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1879729": "Special thanks to the competition host @samy101 !\n\nThis is indeed a small but interesting competition for detecting time-series anomalies. Although I've included various common techiniques and some of them could help improve the score, the feature engineering dominates among all, especially change-of-value features with varying shift steps have significantly positive impact. With only 200 labeled time series for training, the resultant 0.9866 of ROC-AUC score on unseen 206 time series also surprises me. Tree-based model is indeed a beast for regression and classification task : D\n\nMy winning solution is briefly summarized as follows, and the complete script will be soon released to the public in weeks:\n\n**1. Data preprocessing**\n- No anomalies were removed because the goal of this contest is anomaly detection\n- Missing values (NaN) were replaced with the median value of each time series\n\n**2. Feature enegineering**\n- Building meta data and weather data\n- Temporal features (e.g., hour, weekday, and day of year)\n- Target encoding features (ref: preprocessing script from 1st place team in GEPIII)[https://lnkd.in/gdnxRUvz]\n- Change-of-value features: calculate change of value compared to nearby values (e.g., X(t)-X(t-1) and X(t)/X(t-1)) with varying shift steps (from 1 hour to 168 hours))\n- Features from data smoothing and k-means clustering were also tried, but they don’t appear to significantly improve the score\n\n**3. Modeling**\n- Train/valid split by building_id to ensure the valid data were unseen during training\n- Downsampling training dataset to solve data imbalance (~5% of anomalies): normal values : abnormal values = 1:1\n- Model ensembling via simple averaging: XGBosst, LightGBM, CatBoost, and HistGradientBoosting (weight of 0.25 for each)\n\n**4. Postprocessing**\n- Set zeros to rows with 1.0 of meter_reading\n- Set zeros to start and end points of time series\n\nHope this can help : )",
    "1882385": "Yes, this is helpful. Congratulations for your position! Thanks for the summary!",
    "1882413": "Thanks and that's my pleasure : )",
    "1888794": "Congratulations on your win! This is a great summary of your solution and will be very helpful for others looking to learn from your approach. \n\nThe Devastator."
  },
  "source": "existing_discussion",
  "complete": true,
  "competition_id": 35297,
  "competition_slug": "energy-anomaly-detection",
  "team_id": 8625943,
  "solution_url": "/competitions/energy-anomaly-detection/writeups/chun-fu-summary-of-1st-place-solution"
}