{
  "id": 466573,
  "title": "Ablation Study on Publicly-Shared Solutions through Late Submission",
  "url": "/competitions/child-mind-institute-detect-sleep-states/writeups/bilzard-ablation-study-on-publicly-shared-solution",
  "author_name": "",
  "post_date": "2024-01-09T13:14:37.103Z",
  "votes": 16,
  "comment_count": 1,
  "views": 0,
  "content": "<h2>Overview</h2>\n<p>This report presents the results of an ablation study that I conducted locally and on the LB by incorporating ideas from solutions shared in the public discussion after the closure of the Kaggle competition <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states\" target=\"_blank\">Child Mind Institute - Detect Sleep States</a>.</p>\n<h2>Pipeline</h2>\n<p>The pipeline is similar to that described in [3]. The model, based on a 1D-CNN at the 1st stage, predicts the probability of onset/wakeup events for each steps, which is then post-processed into table data and further regressed with GBDT (Gradient Boosting Decision Tree) model by adding aggregated features of series/night.</p>\n<p>It is important to note that in a multi-stage model, the pipeline sometimes become slightly different between training and inference phases. Therefore, eliminating domain shift in both the input features and the output results of the 2nd stage model during training and inference is crucial.</p>\n<p>For example, in this ablation study, the average of the event probability predictions from 3 seeds per fold was calculated during training, and the results of the post-processing were used as input features. In contrast, during inference, the average of event probability predictions from 15 models (3 seeds x 5 folds) was used as input features (similar settings were employed in [2, 3]).</p>\n<p>On the other hand, in my initial pipeline before starting this ablation study, I used the WBF (Weighted Box Fusion) ensemble results for each fold based on the average event probability predictions from 3 seeds as input features for the 2nd stage model. This configuration significantly worsened the correlation between local validation results and LB (Figure 2). The possible reason for this could be the domain shift in input features; the <code>step</code> optimized for AP used during training was shifted from its optimal point due to the ensemble with WBF during inference.</p>\n<p>Based on such a hypothesis and switching to a pipeline similar to [2, 3], I was able to restore the correlation between local validation results and LB to the same level as before applying the 2nd stage model.</p>\n<p>Thus, I leaned that in a multi-stage model, it is crucial to design the sequence of inputs and outputs to minimize domain shift between training and inference phases.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2Fb5d384215833d8ef12b51cb9b1f4e84e%2Fcmi_pipeline.svg?generation=1704803887493821&amp;alt=media\"></p>\n<p><strong>Figure 1. Overall Configuration of the 2-stage Pipeline</strong></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F4227916f1645584f265809cbc676f222%2Fcmi_cv_lb_correlation.svg?generation=1704803960433173&amp;alt=media\"></p>\n<p><strong>Figure 2. CB-LB Correlation over Different Pipeline Settings</strong></p>\n<h2>1st Stage</h2>\n<h3>Input Features</h3>\n<p>In addition to the features used in [1], I added the <code>minute % 15</code> feature which was claimed to be effective in [2]. Thus I utilized 6 features listed below.</p>\n<p><strong>numerical</strong></p>\n<ul>\n<li><code>log_anglez_std_2min</code>: The logarithm of the rolling standard deviation of angle-z over a 2-minute interval.</li>\n<li><code>log_enmo</code>: The logarithm of ENMO.</li>\n<li><code>hour_sin</code>: Positional encoding of the hour within one night.</li>\n<li><code>hour_cos</code>: Positional encoding of the hour within one night.</li>\n</ul>\n<p><strong>categorical</strong></p>\n<ul>\n<li><code>is_valid</code>: A flag indicating whether the data is imputed or not. (1: normal data, 0: imputed data)</li>\n<li><code>min_mod_15_plus_1</code>: minute % 15 + 1 (1-15: normal data, 0: padded data)</li>\n</ul>\n<h3>Model Architecture</h3>\n<p>The design is based on [2]. To reduce computation, I used the strides larger than in the original solution. Additionally, by adding the average-pooled feature maps from the raw series to the U-Net encoder, which is used in [1], significantly improved learning convergence and stabilization.</p>\n<p>Note that this model is very lightweight, with the checkpoint size being only 3.5MB per model, totaling 54MB for 15 models. The training time is about 6 minutes per model for 20 epochs, and it takes about 1.5 hours for all 15 models using Nvidia RTX4090. Furthermore, the scoring time on Kaggle Notebook for the entire pipeline was approximately 20 minutes.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F145f459b4db889e7a678d4417f0b43cd%2Fcmi_1st_stage_architecture.svg?generation=1704803853869284&amp;alt=media\"></p>\n<p><strong>Figure 3. The architecture of the 1st stage model</strong></p>\n<h3>AP-Optimized Postprocessing</h3>\n<p>I made some improvements to the AP evaluation metric-optimized postprocessing that was shared in [2].</p>\n<p>In [2], they computed the rolling sum of scores within a window of <code>k=2 * (tolerance_quarter_minute - 1) + 1</code>, whereas in this ablation study, I used rolling mean to aggregate scores of quarter points in each tolerance range. Since the total score aggregated by the rolling sum is proportional to the window size, it gives more weight to windows with greater tolerance. By using the rolling mean as the aggregation function, it's possible to mitigate the bias in weights for each tolerance.</p>\n<h2>2nd Stage</h2>\n<h3>Model</h3>\n<p>I created a regression model using XGBoost[6].</p>\n<h3>Input Features</h3>\n<p>I utilized the following 14 features. All are extracted solely from the 1st stage model's prediction results (<code>series_id</code>, <code>event</code>, <code>night_id</code>, <code>step</code>, <code>score</code>), without using the original series features. The importance of these features are visualized in Figure 4.</p>\n<ul>\n<li><code>event</code></li>\n<li><code>rel_night_id</code></li>\n<li><code>valid_rate_per_night</code></li>\n<li><code>valid_rate_per_series</code></li>\n<li><code>confidence</code></li>\n<li><code>rank_per_night</code></li>\n<li><code>mean_confidence_per_night</code></li>\n<li><code>mean_confidence_per_series</code></li>\n<li><code>norm_confidence_per_night</code></li>\n<li><code>norm_confidence_per_series</code></li>\n<li><code>abs_min_diff_from_HDCZA</code> [4]</li>\n<li><code>abs_min_diff_from_top_0</code></li>\n<li><code>sum_confidence_per_night</code></li>\n<li><code>confidence_normalized_by_mean_per_night</code></li>\n</ul>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F485962d7022b3611992cf7d254dcfd43%2Fcmi_feature_importance_of_2nd_stage_features.png?generation=1704806006943498&amp;alt=media\"></p>\n<p><strong>Figure 4. Importance of 2nd Stage Features</strong></p>\n<h3>Target</h3>\n<p>The design of the label was inspired by [3]. The difference is that while [3] used top-k accuracy as the target in training phase, then applies diff of top-k accuracy as predicted score in inference phase, this ablation study regressed diff of top-k accuracy directly. Furthermore, the original implementation supplied binary labels by fixed threshold, but in this study, I used soft labels with logistic regression. The local validation results showed a slightly higher AP score with this configuration.</p>\n<h2>Ablation Study</h2>\n<p>The results of the Ablation Study are shown in Table 1.</p>\n<p>The largest impact was observed from ablating the flag indicating whether the data was imputed or not (AP=-0.0236), presumably because the model generated many False Positives due to features indicative of spurious onset/wakeup. Note that the ablation of the flag for imputed data was achieved by providing <code>is_valid=1</code> for all series during inference, using a model that is trained <em>including</em> the <code>is_valid</code> feature. This is because I wanted to save time for training another models. Note that this settings can be slightly different to the result of the model <em>without</em> <code>is_valid</code> feature both training and inference phases.</p>\n<p>The contributions of the AP-optimized postprocessing and the ablation of the 2nd stage model were roughly equivalent (each reducing the local AP by -0.0075 and -0.0071, respectively).</p>\n<p>The algorithm used in the original [2] (AP Optimization with rolling summation) alone decreased AP (local AP by -0.0144), but could be somewhat restored in performance by the 2nd stage model (local AP by -0.0016). However, I couldn't observe positive gain over the baseline using <code>find_peak</code>. Thus, this ablation study failed to achieve the huge gain as reported in [2] with the 2nd stage model. This is possibly due to not feeding the original input series features to the 2nd stage models. Feeding with richer input features could improve 2nd stage models higher beyond.</p>\n<p>Importantly, as shown in this case, the impact of postprocessing which is optimized for the specific evaluation metrics <em>can be significant</em>. In tasks where AP is used as the evaluation metric for models (e.g., object detection tasks), substantial gains might be achieved through such kind of postprocessing, as used in [2] and this ablation study. Conversely, this also means evaluating solely on the AP metric might make it difficult to distinguish whether the results are evaluating the model's performance itself or an (over-)optimized outcome for the specific evaluation metrics. In the case of object detection tasks, fortunately, most literature applies only simple postprocessing, such as NMS (Non-Maximum Suppression), so the impact might not be as severe as I concerned. However, there are some examples, like DETR[5], which employ tricks such as allocating empty object query slots for predicting a second probable candidate bounding boxes to boost AP scores. When evaluating such models, careful judgment is required to determine whether the results are attributable to the model's performance itself or the results of postprocessing optimized for specific metrics.</p>\n<p><strong>Table 1. Results of the ablation study:</strong></p>\n<table>\n<thead>\n<tr>\n<th>w <code>is_valid</code> feature</th>\n<th>w AP Optimization (Sum)</th>\n<th>w AP Optimization (Avg)</th>\n<th>w 2nd Stage (Weight=0.2)</th>\n<th>w 2nd Stage (Weight=1.0)</th>\n<th>AP Local (OOF)</th>\n<th>LB Public</th>\n<th>LB Private</th>\n<th>Scoring Time (min)</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td>0.79</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td>0.8136</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td>x</td>\n<td></td>\n<td></td>\n<td></td>\n<td>0.7992</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td></td>\n<td>0.8009</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td>x</td>\n<td></td>\n<td></td>\n<td>x</td>\n<td>0.812</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td></td>\n<td></td>\n<td>0.8211</td>\n<td>0.772</td>\n<td>0.833</td>\n<td>22</td>\n</tr>\n<tr>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td>0.8263</td>\n<td>0.77</td>\n<td>0.838</td>\n<td>20</td>\n</tr>\n<tr>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td>x</td>\n<td></td>\n<td>0.8282</td>\n<td>0.777</td>\n<td>0.838</td>\n<td>20</td>\n</tr>\n</tbody>\n</table>\n<h2>What Didn't Work</h2>\n<p>For the input features of the 2nd stage, I tried adding target encoding features based on the overall distribution of Ground truth, such as event timing, inspired by the idea in [1]. However, this did not improve the local validation score.</p>\n<p>Regarding the features of the 2nd stage model, I also tested patterns using features similar to those used in [3], but this slightly worsened the local AP. Additionally, while some features improved the local validation score, they worsened the LB score. This stage's model is prone to overfitting and domain shift effects, so careful design of features is necessary.</p>\n<h2>Acknowledgements</h2>\n<p>I would like to express my gratitude to the hosts who organized the competition and to everyone at Kaggle management. I also extend my thanks to all the participants who shared their solutions and ideas.</p>\n<h2>Reference</h2>\n<ul>\n<li>[1] <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/460274\" target=\"_blank\">14th place solution by Jack</a></li>\n<li>[2] <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/459715\" target=\"_blank\">1st place solution by shimacos, sakami, and kami</a></li>\n<li>[3] <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/459627\" target=\"_blank\">2nd place solution by K-mat</a></li>\n<li>[4] <a href=\"https://www.kaggle.com/code/tatamikenn/sleep-hdcza-a-pure-heuristic-approach-lb-0-447\" target=\"_blank\">https://www.kaggle.com/code/tatamikenn/sleep-hdcza-a-pure-heuristic-approach-lb-0-447</a></li>\n<li>[5] <a href=\"https://ai.meta.com/research/publications/end-to-end-object-detection-with-transformers/\" target=\"_blank\">End-to-end object detection with Transformers</a></li>\n<li>[6] <a href=\"https://xgboost.readthedocs.io/en/stable\" target=\"_blank\">https://xgboost.readthedocs.io/en/stable</a></li>\n</ul>",
  "messages": [
    {
      "id": "2593346",
      "postDate": "01/09/2024 07:20:47",
      "content": "<h2>Overview</h2>\n<p>This report presents the results of an ablation study that I conducted locally and on the LB by incorporating ideas from solutions shared in the public discussion after the closure of the Kaggle competition <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states\" target=\"_blank\">Child Mind Institute - Detect Sleep States</a>.</p>\n<h2>Pipeline</h2>\n<p>The pipeline is similar to that described in [3]. The model, based on a 1D-CNN at the 1st stage, predicts the probability of onset/wakeup events for each steps, which is then post-processed into table data and further regressed with GBDT (Gradient Boosting Decision Tree) model by adding aggregated features of series/night.</p>\n<p>It is important to note that in a multi-stage model, the pipeline sometimes become slightly different between training and inference phases. Therefore, eliminating domain shift in both the input features and the output results of the 2nd stage model during training and inference is crucial.</p>\n<p>For example, in this ablation study, the average of the event probability predictions from 3 seeds per fold was calculated during training, and the results of the post-processing were used as input features. In contrast, during inference, the average of event probability predictions from 15 models (3 seeds x 5 folds) was used as input features (similar settings were employed in [2, 3]).</p>\n<p>On the other hand, in my initial pipeline before starting this ablation study, I used the WBF (Weighted Box Fusion) ensemble results for each fold based on the average event probability predictions from 3 seeds as input features for the 2nd stage model. This configuration significantly worsened the correlation between local validation results and LB (Figure 2). The possible reason for this could be the domain shift in input features; the <code>step</code> optimized for AP used during training was shifted from its optimal point due to the ensemble with WBF during inference.</p>\n<p>Based on such a hypothesis and switching to a pipeline similar to [2, 3], I was able to restore the correlation between local validation results and LB to the same level as before applying the 2nd stage model.</p>\n<p>Thus, I leaned that in a multi-stage model, it is crucial to design the sequence of inputs and outputs to minimize domain shift between training and inference phases.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2Fb5d384215833d8ef12b51cb9b1f4e84e%2Fcmi_pipeline.svg?generation=1704803887493821&amp;alt=media\"></p>\n<p><strong>Figure 1. Overall Configuration of the 2-stage Pipeline</strong></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F4227916f1645584f265809cbc676f222%2Fcmi_cv_lb_correlation.svg?generation=1704803960433173&amp;alt=media\"></p>\n<p><strong>Figure 2. CB-LB Correlation over Different Pipeline Settings</strong></p>\n<h2>1st Stage</h2>\n<h3>Input Features</h3>\n<p>In addition to the features used in [1], I added the <code>minute % 15</code> feature which was claimed to be effective in [2]. Thus I utilized 6 features listed below.</p>\n<p><strong>numerical</strong></p>\n<ul>\n<li><code>log_anglez_std_2min</code>: The logarithm of the rolling standard deviation of angle-z over a 2-minute interval.</li>\n<li><code>log_enmo</code>: The logarithm of ENMO.</li>\n<li><code>hour_sin</code>: Positional encoding of the hour within one night.</li>\n<li><code>hour_cos</code>: Positional encoding of the hour within one night.</li>\n</ul>\n<p><strong>categorical</strong></p>\n<ul>\n<li><code>is_valid</code>: A flag indicating whether the data is imputed or not. (1: normal data, 0: imputed data)</li>\n<li><code>min_mod_15_plus_1</code>: minute % 15 + 1 (1-15: normal data, 0: padded data)</li>\n</ul>\n<h3>Model Architecture</h3>\n<p>The design is based on [2]. To reduce computation, I used the strides larger than in the original solution. Additionally, by adding the average-pooled feature maps from the raw series to the U-Net encoder, which is used in [1], significantly improved learning convergence and stabilization.</p>\n<p>Note that this model is very lightweight, with the checkpoint size being only 3.5MB per model, totaling 54MB for 15 models. The training time is about 6 minutes per model for 20 epochs, and it takes about 1.5 hours for all 15 models using Nvidia RTX4090. Furthermore, the scoring time on Kaggle Notebook for the entire pipeline was approximately 20 minutes.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F145f459b4db889e7a678d4417f0b43cd%2Fcmi_1st_stage_architecture.svg?generation=1704803853869284&amp;alt=media\"></p>\n<p><strong>Figure 3. The architecture of the 1st stage model</strong></p>\n<h3>AP-Optimized Postprocessing</h3>\n<p>I made some improvements to the AP evaluation metric-optimized postprocessing that was shared in [2].</p>\n<p>In [2], they computed the rolling sum of scores within a window of <code>k=2 * (tolerance_quarter_minute - 1) + 1</code>, whereas in this ablation study, I used rolling mean to aggregate scores of quarter points in each tolerance range. Since the total score aggregated by the rolling sum is proportional to the window size, it gives more weight to windows with greater tolerance. By using the rolling mean as the aggregation function, it's possible to mitigate the bias in weights for each tolerance.</p>\n<h2>2nd Stage</h2>\n<h3>Model</h3>\n<p>I created a regression model using XGBoost[6].</p>\n<h3>Input Features</h3>\n<p>I utilized the following 14 features. All are extracted solely from the 1st stage model's prediction results (<code>series_id</code>, <code>event</code>, <code>night_id</code>, <code>step</code>, <code>score</code>), without using the original series features. The importance of these features are visualized in Figure 4.</p>\n<ul>\n<li><code>event</code></li>\n<li><code>rel_night_id</code></li>\n<li><code>valid_rate_per_night</code></li>\n<li><code>valid_rate_per_series</code></li>\n<li><code>confidence</code></li>\n<li><code>rank_per_night</code></li>\n<li><code>mean_confidence_per_night</code></li>\n<li><code>mean_confidence_per_series</code></li>\n<li><code>norm_confidence_per_night</code></li>\n<li><code>norm_confidence_per_series</code></li>\n<li><code>abs_min_diff_from_HDCZA</code> [4]</li>\n<li><code>abs_min_diff_from_top_0</code></li>\n<li><code>sum_confidence_per_night</code></li>\n<li><code>confidence_normalized_by_mean_per_night</code></li>\n</ul>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F485962d7022b3611992cf7d254dcfd43%2Fcmi_feature_importance_of_2nd_stage_features.png?generation=1704806006943498&amp;alt=media\"></p>\n<p><strong>Figure 4. Importance of 2nd Stage Features</strong></p>\n<h3>Target</h3>\n<p>The design of the label was inspired by [3]. The difference is that while [3] used top-k accuracy as the target in training phase, then applies diff of top-k accuracy as predicted score in inference phase, this ablation study regressed diff of top-k accuracy directly. Furthermore, the original implementation supplied binary labels by fixed threshold, but in this study, I used soft labels with logistic regression. The local validation results showed a slightly higher AP score with this configuration.</p>\n<h2>Ablation Study</h2>\n<p>The results of the Ablation Study are shown in Table 1.</p>\n<p>The largest impact was observed from ablating the flag indicating whether the data was imputed or not (AP=-0.0236), presumably because the model generated many False Positives due to features indicative of spurious onset/wakeup. Note that the ablation of the flag for imputed data was achieved by providing <code>is_valid=1</code> for all series during inference, using a model that is trained <em>including</em> the <code>is_valid</code> feature. This is because I wanted to save time for training another models. Note that this settings can be slightly different to the result of the model <em>without</em> <code>is_valid</code> feature both training and inference phases.</p>\n<p>The contributions of the AP-optimized postprocessing and the ablation of the 2nd stage model were roughly equivalent (each reducing the local AP by -0.0075 and -0.0071, respectively).</p>\n<p>The algorithm used in the original [2] (AP Optimization with rolling summation) alone decreased AP (local AP by -0.0144), but could be somewhat restored in performance by the 2nd stage model (local AP by -0.0016). However, I couldn't observe positive gain over the baseline using <code>find_peak</code>. Thus, this ablation study failed to achieve the huge gain as reported in [2] with the 2nd stage model. This is possibly due to not feeding the original input series features to the 2nd stage models. Feeding with richer input features could improve 2nd stage models higher beyond.</p>\n<p>Importantly, as shown in this case, the impact of postprocessing which is optimized for the specific evaluation metrics <em>can be significant</em>. In tasks where AP is used as the evaluation metric for models (e.g., object detection tasks), substantial gains might be achieved through such kind of postprocessing, as used in [2] and this ablation study. Conversely, this also means evaluating solely on the AP metric might make it difficult to distinguish whether the results are evaluating the model's performance itself or an (over-)optimized outcome for the specific evaluation metrics. In the case of object detection tasks, fortunately, most literature applies only simple postprocessing, such as NMS (Non-Maximum Suppression), so the impact might not be as severe as I concerned. However, there are some examples, like DETR[5], which employ tricks such as allocating empty object query slots for predicting a second probable candidate bounding boxes to boost AP scores. When evaluating such models, careful judgment is required to determine whether the results are attributable to the model's performance itself or the results of postprocessing optimized for specific metrics.</p>\n<p><strong>Table 1. Results of the ablation study:</strong></p>\n<table>\n<thead>\n<tr>\n<th>w <code>is_valid</code> feature</th>\n<th>w AP Optimization (Sum)</th>\n<th>w AP Optimization (Avg)</th>\n<th>w 2nd Stage (Weight=0.2)</th>\n<th>w 2nd Stage (Weight=1.0)</th>\n<th>AP Local (OOF)</th>\n<th>LB Public</th>\n<th>LB Private</th>\n<th>Scoring Time (min)</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td>0.79</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td>0.8136</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td>x</td>\n<td></td>\n<td></td>\n<td></td>\n<td>0.7992</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td></td>\n<td>0.8009</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td>x</td>\n<td></td>\n<td></td>\n<td>x</td>\n<td>0.812</td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td></td>\n<td></td>\n<td>0.8211</td>\n<td>0.772</td>\n<td>0.833</td>\n<td>22</td>\n</tr>\n<tr>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td>0.8263</td>\n<td>0.77</td>\n<td>0.838</td>\n<td>20</td>\n</tr>\n<tr>\n<td>x</td>\n<td></td>\n<td>x</td>\n<td>x</td>\n<td></td>\n<td>0.8282</td>\n<td>0.777</td>\n<td>0.838</td>\n<td>20</td>\n</tr>\n</tbody>\n</table>\n<h2>What Didn't Work</h2>\n<p>For the input features of the 2nd stage, I tried adding target encoding features based on the overall distribution of Ground truth, such as event timing, inspired by the idea in [1]. However, this did not improve the local validation score.</p>\n<p>Regarding the features of the 2nd stage model, I also tested patterns using features similar to those used in [3], but this slightly worsened the local AP. Additionally, while some features improved the local validation score, they worsened the LB score. This stage's model is prone to overfitting and domain shift effects, so careful design of features is necessary.</p>\n<h2>Acknowledgements</h2>\n<p>I would like to express my gratitude to the hosts who organized the competition and to everyone at Kaggle management. I also extend my thanks to all the participants who shared their solutions and ideas.</p>\n<h2>Reference</h2>\n<ul>\n<li>[1] <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/460274\" target=\"_blank\">14th place solution by Jack</a></li>\n<li>[2] <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/459715\" target=\"_blank\">1st place solution by shimacos, sakami, and kami</a></li>\n<li>[3] <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/459627\" target=\"_blank\">2nd place solution by K-mat</a></li>\n<li>[4] <a href=\"https://www.kaggle.com/code/tatamikenn/sleep-hdcza-a-pure-heuristic-approach-lb-0-447\" target=\"_blank\">https://www.kaggle.com/code/tatamikenn/sleep-hdcza-a-pure-heuristic-approach-lb-0-447</a></li>\n<li>[5] <a href=\"https://ai.meta.com/research/publications/end-to-end-object-detection-with-transformers/\" target=\"_blank\">End-to-end object detection with Transformers</a></li>\n<li>[6] <a href=\"https://xgboost.readthedocs.io/en/stable\" target=\"_blank\">https://xgboost.readthedocs.io/en/stable</a></li>\n</ul>",
      "rawMarkdown": "## Overview\n\nThis report presents the results of an ablation study that I conducted locally and on the LB by incorporating ideas from solutions shared in the public discussion after the closure of the Kaggle competition [Child Mind Institute - Detect Sleep States](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states).\n\n## Pipeline\n\nThe pipeline is similar to that described in [3]. The model, based on a 1D-CNN at the 1st stage, predicts the probability of onset/wakeup events for each steps, which is then post-processed into table data and further regressed with GBDT (Gradient Boosting Decision Tree) model by adding aggregated features of series/night.\n\nIt is important to note that in a multi-stage model, the pipeline sometimes become slightly different between training and inference phases. Therefore, eliminating domain shift in both the input features and the output results of the 2nd stage model during training and inference is crucial.\n\nFor example, in this ablation study, the average of the event probability predictions from 3 seeds per fold was calculated during training, and the results of the post-processing were used as input features. In contrast, during inference, the average of event probability predictions from 15 models (3 seeds x 5 folds) was used as input features (similar settings were employed in [2, 3]).\n\nOn the other hand, in my initial pipeline before starting this ablation study, I used the WBF (Weighted Box Fusion) ensemble results for each fold based on the average event probability predictions from 3 seeds as input features for the 2nd stage model. This configuration significantly worsened the correlation between local validation results and LB (Figure 2). The possible reason for this could be the domain shift in input features; the `step` optimized for AP used during training was shifted from its optimal point due to the ensemble with WBF during inference.\n\nBased on such a hypothesis and switching to a pipeline similar to [2, 3], I was able to restore the correlation between local validation results and LB to the same level as before applying the 2nd stage model.\n\nThus, I leaned that in a multi-stage model, it is crucial to design the sequence of inputs and outputs to minimize domain shift between training and inference phases.\n\n\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2Fb5d384215833d8ef12b51cb9b1f4e84e%2Fcmi_pipeline.svg?generation=1704803887493821&alt=media\" width=\"480px\" />\n\n**Figure 1. Overall Configuration of the 2-stage Pipeline**\n\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F4227916f1645584f265809cbc676f222%2Fcmi_cv_lb_correlation.svg?generation=1704803960433173&alt=media\" width=480px />\n\n**Figure 2. CB-LB Correlation over Different Pipeline Settings**\n\n## 1st Stage\n\n### Input Features\n\nIn addition to the features used in [1], I added the `minute % 15` feature which was claimed to be effective in [2]. Thus I utilized 6 features listed below.\n\n**numerical**\n\n- `log_anglez_std_2min`: The logarithm of the rolling standard deviation of angle-z over a 2-minute interval.\n- `log_enmo`: The logarithm of ENMO.\n- `hour_sin`: Positional encoding of the hour within one night.\n- `hour_cos`: Positional encoding of the hour within one night.\n\n**categorical**\n\n- `is_valid`: A flag indicating whether the data is imputed or not. (1: normal data, 0: imputed data)\n- `min_mod_15_plus_1`: minute % 15 + 1 (1-15: normal data, 0: padded data)\n\n### Model Architecture\n\nThe design is based on [2]. To reduce computation, I used the strides larger than in the original solution. Additionally, by adding the average-pooled feature maps from the raw series to the U-Net encoder, which is used in [1], significantly improved learning convergence and stabilization.\n\nNote that this model is very lightweight, with the checkpoint size being only 3.5MB per model, totaling 54MB for 15 models. The training time is about 6 minutes per model for 20 epochs, and it takes about 1.5 hours for all 15 models using Nvidia RTX4090. Furthermore, the scoring time on Kaggle Notebook for the entire pipeline was approximately 20 minutes.\n\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F145f459b4db889e7a678d4417f0b43cd%2Fcmi_1st_stage_architecture.svg?generation=1704803853869284&alt=media\" width=\"480px\" />\n\n**Figure 3. The architecture of the 1st stage model**\n\n### AP-Optimized Postprocessing\n\nI made some improvements to the AP evaluation metric-optimized postprocessing that was shared in [2].\n\nIn [2], they computed the rolling sum of scores within a window of `k=2 * (tolerance_quarter_minute - 1) + 1`, whereas in this ablation study, I used rolling mean to aggregate scores of quarter points in each tolerance range. Since the total score aggregated by the rolling sum is proportional to the window size, it gives more weight to windows with greater tolerance. By using the rolling mean as the aggregation function, it's possible to mitigate the bias in weights for each tolerance.\n\n## 2nd Stage\n\n### Model\n\nI created a regression model using XGBoost[6].\n\n### Input Features\n\nI utilized the following 14 features. All are extracted solely from the 1st stage model's prediction results (`series_id`, `event`, `night_id`, `step`, `score`), without using the original series features. The importance of these features are visualized in Figure 4.\n\n- `event`\n- `rel_night_id`\n- `valid_rate_per_night`\n- `valid_rate_per_series`\n- `confidence`\n- `rank_per_night`\n- `mean_confidence_per_night`\n- `mean_confidence_per_series`\n- `norm_confidence_per_night`\n- `norm_confidence_per_series`\n- `abs_min_diff_from_HDCZA` [4]\n- `abs_min_diff_from_top_0`\n- `sum_confidence_per_night`\n- `confidence_normalized_by_mean_per_night`\n\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F485962d7022b3611992cf7d254dcfd43%2Fcmi_feature_importance_of_2nd_stage_features.png?generation=1704806006943498&alt=media\" width=\"640px\" />\n\n**Figure 4. Importance of 2nd Stage Features**\n\n### Target\n\nThe design of the label was inspired by [3]. The difference is that while [3] used top-k accuracy as the target in training phase, then applies diff of top-k accuracy as predicted score in inference phase, this ablation study regressed diff of top-k accuracy directly. Furthermore, the original implementation supplied binary labels by fixed threshold, but in this study, I used soft labels with logistic regression. The local validation results showed a slightly higher AP score with this configuration.\n\n## Ablation Study\n\nThe results of the Ablation Study are shown in Table 1.\n\nThe largest impact was observed from ablating the flag indicating whether the data was imputed or not (AP=-0.0236), presumably because the model generated many False Positives due to features indicative of spurious onset/wakeup. Note that the ablation of the flag for imputed data was achieved by providing `is_valid=1` for all series during inference, using a model that is trained *including* the `is_valid` feature. This is because I wanted to save time for training another models. Note that this settings can be slightly different to the result of the model *without* `is_valid` feature both training and inference phases.\n\nThe contributions of the AP-optimized postprocessing and the ablation of the 2nd stage model were roughly equivalent (each reducing the local AP by -0.0075 and -0.0071, respectively).\n\nThe algorithm used in the original [2] (AP Optimization with rolling summation) alone decreased AP (local AP by -0.0144), but could be somewhat restored in performance by the 2nd stage model (local AP by -0.0016). However, I couldn't observe positive gain over the baseline using `find_peak`. Thus, this ablation study failed to achieve the huge gain as reported in [2] with the 2nd stage model. This is possibly due to not feeding the original input series features to the 2nd stage models. Feeding with richer input features could improve 2nd stage models higher beyond.\n\nImportantly, as shown in this case, the impact of postprocessing which is optimized for the specific evaluation metrics *can be significant*. In tasks where AP is used as the evaluation metric for models (e.g., object detection tasks), substantial gains might be achieved through such kind of postprocessing, as used in [2] and this ablation study. Conversely, this also means evaluating solely on the AP metric might make it difficult to distinguish whether the results are evaluating the model's performance itself or an (over-)optimized outcome for the specific evaluation metrics. In the case of object detection tasks, fortunately, most literature applies only simple postprocessing, such as NMS (Non-Maximum Suppression), so the impact might not be as severe as I concerned. However, there are some examples, like DETR[5], which employ tricks such as allocating empty object query slots for predicting a second probable candidate bounding boxes to boost AP scores. When evaluating such models, careful judgment is required to determine whether the results are attributable to the model's performance itself or the results of postprocessing optimized for specific metrics.\n\n**Table 1. Results of the ablation study:**\n\n| w `is_valid` feature | w AP Optimization (Sum) | w AP Optimization (Avg) | w 2nd Stage (Weight=0.2) | w 2nd Stage (Weight=1.0) | AP Local (OOF) | LB Public | LB Private | Scoring Time (min) |\n| -------------------- | ----------------------- | ----------------------- | ------------------------ | ------------------------ | -------------- | --------- | ---------- | --------------------- |\n|                      |                         |                         |                          |                          | 0.79           |           |            |                       |\n| x                    |                         |                         |                          |                          | 0.8136         |           |            |                       |\n| x                    | x                       |                         |                          |                          | 0.7992         |           |            |                       |\n| x                    | x                       |                         | x                        |                          | 0.8009         |           |            |                       |\n| x                    | x                       |                         |                          | x                        | 0.812          |           |            |                       |\n| x                    |                         | x                       |                          |                          | 0.8211         | 0.772     | 0.833      | 22                    |\n| x                    |                         | x                       |                          | x                        | 0.8263         | 0.77      | 0.838      | 20                    |\n| x                    |                         | x                       | x                        |                          | 0.8282         | 0.777     | 0.838      | 20                    |\n\n## What Didn't Work\n\nFor the input features of the 2nd stage, I tried adding target encoding features based on the overall distribution of Ground truth, such as event timing, inspired by the idea in [1]. However, this did not improve the local validation score.\n\nRegarding the features of the 2nd stage model, I also tested patterns using features similar to those used in [3], but this slightly worsened the local AP. Additionally, while some features improved the local validation score, they worsened the LB score. This stage's model is prone to overfitting and domain shift effects, so careful design of features is necessary.\n\n## Acknowledgements\n\nI would like to express my gratitude to the hosts who organized the competition and to everyone at Kaggle management. I also extend my thanks to all the participants who shared their solutions and ideas.\n\n## Reference\n\n- [1] [14th place solution by Jack](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/460274)\n- [2] [1st place solution by shimacos, sakami, and kami](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/459715)\n- [3] [2nd place solution by K-mat](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/459627)\n- [4] https://www.kaggle.com/code/tatamikenn/sleep-hdcza-a-pure-heuristic-approach-lb-0-447\n- [5] [End-to-end object detection with Transformers](https://ai.meta.com/research/publications/end-to-end-object-detection-with-transformers/)\n- [6] https://xgboost.readthedocs.io/en/stable",
      "votes": null
    },
    {
      "id": "2593809",
      "postDate": "01/09/2024 13:28:18",
      "content": "<h2>Appendix: The visualization of 2nd stage model's predictions</h2>\n<p>The below are the visualization of 1st stage scores and 2nd scores sampled from night chunks. In the general tendency, the model fails to increase confidence of lower-ranked predictions where the GT events are placed nearby. However, it seems to succeed in increasing the confidence of 1st models for higher-ranked predictions. This can be because of with the information gained from aggregated features over <code>series_id</code> or <code>night_id</code>, they can successfully decide whether and how much confidence the 2nd model should increase over these predictions.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2Feb754f608959c110eb45a1395de40f38%2Fsample_01.png?generation=1704806148833178&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F82320fe1c18d896e2817f5496fd6e745%2Fsample_02.png?generation=1704806160612952&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F644ff610a10ee6039e4b8de00b7746e7%2Fsample_03.png?generation=1704806469987441&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "## Appendix: The visualization of 2nd stage model's predictions\n\nThe below are the visualization of 1st stage scores and 2nd scores sampled from night chunks. In the general tendency, the model fails to increase confidence of lower-ranked predictions where the GT events are placed nearby. However, it seems to succeed in increasing the confidence of 1st models for higher-ranked predictions. This can be because of with the information gained from aggregated features over `series_id` or `night_id`, they can successfully decide whether and how much confidence the 2nd model should increase over these predictions.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2Feb754f608959c110eb45a1395de40f38%2Fsample_01.png?generation=1704806148833178&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F82320fe1c18d896e2817f5496fd6e745%2Fsample_02.png?generation=1704806160612952&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F644ff610a10ee6039e4b8de00b7746e7%2Fsample_03.png?generation=1704806469987441&alt=media)",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2593809,
      "author_name": "tatamikenn",
      "author_url": "",
      "post_date": "01/09/2024 13:28:18",
      "content": "<h2>Appendix: The visualization of 2nd stage model's predictions</h2>\n<p>The below are the visualization of 1st stage scores and 2nd scores sampled from night chunks. In the general tendency, the model fails to increase confidence of lower-ranked predictions where the GT events are placed nearby. However, it seems to succeed in increasing the confidence of 1st models for higher-ranked predictions. This can be because of with the information gained from aggregated features over <code>series_id</code> or <code>night_id</code>, they can successfully decide whether and how much confidence the 2nd model should increase over these predictions.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2Feb754f608959c110eb45a1395de40f38%2Fsample_01.png?generation=1704806148833178&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F82320fe1c18d896e2817f5496fd6e745%2Fsample_02.png?generation=1704806160612952&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F644ff610a10ee6039e4b8de00b7746e7%2Fsample_03.png?generation=1704806469987441&amp;alt=media\" alt=\"\"></p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2593346": "## Overview\n\nThis report presents the results of an ablation study that I conducted locally and on the LB by incorporating ideas from solutions shared in the public discussion after the closure of the Kaggle competition [Child Mind Institute - Detect Sleep States](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states).\n\n## Pipeline\n\nThe pipeline is similar to that described in [3]. The model, based on a 1D-CNN at the 1st stage, predicts the probability of onset/wakeup events for each steps, which is then post-processed into table data and further regressed with GBDT (Gradient Boosting Decision Tree) model by adding aggregated features of series/night.\n\nIt is important to note that in a multi-stage model, the pipeline sometimes become slightly different between training and inference phases. Therefore, eliminating domain shift in both the input features and the output results of the 2nd stage model during training and inference is crucial.\n\nFor example, in this ablation study, the average of the event probability predictions from 3 seeds per fold was calculated during training, and the results of the post-processing were used as input features. In contrast, during inference, the average of event probability predictions from 15 models (3 seeds x 5 folds) was used as input features (similar settings were employed in [2, 3]).\n\nOn the other hand, in my initial pipeline before starting this ablation study, I used the WBF (Weighted Box Fusion) ensemble results for each fold based on the average event probability predictions from 3 seeds as input features for the 2nd stage model. This configuration significantly worsened the correlation between local validation results and LB (Figure 2). The possible reason for this could be the domain shift in input features; the `step` optimized for AP used during training was shifted from its optimal point due to the ensemble with WBF during inference.\n\nBased on such a hypothesis and switching to a pipeline similar to [2, 3], I was able to restore the correlation between local validation results and LB to the same level as before applying the 2nd stage model.\n\nThus, I leaned that in a multi-stage model, it is crucial to design the sequence of inputs and outputs to minimize domain shift between training and inference phases.\n\n\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2Fb5d384215833d8ef12b51cb9b1f4e84e%2Fcmi_pipeline.svg?generation=1704803887493821&alt=media\" width=\"480px\" />\n\n**Figure 1. Overall Configuration of the 2-stage Pipeline**\n\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F4227916f1645584f265809cbc676f222%2Fcmi_cv_lb_correlation.svg?generation=1704803960433173&alt=media\" width=480px />\n\n**Figure 2. CB-LB Correlation over Different Pipeline Settings**\n\n## 1st Stage\n\n### Input Features\n\nIn addition to the features used in [1], I added the `minute % 15` feature which was claimed to be effective in [2]. Thus I utilized 6 features listed below.\n\n**numerical**\n\n- `log_anglez_std_2min`: The logarithm of the rolling standard deviation of angle-z over a 2-minute interval.\n- `log_enmo`: The logarithm of ENMO.\n- `hour_sin`: Positional encoding of the hour within one night.\n- `hour_cos`: Positional encoding of the hour within one night.\n\n**categorical**\n\n- `is_valid`: A flag indicating whether the data is imputed or not. (1: normal data, 0: imputed data)\n- `min_mod_15_plus_1`: minute % 15 + 1 (1-15: normal data, 0: padded data)\n\n### Model Architecture\n\nThe design is based on [2]. To reduce computation, I used the strides larger than in the original solution. Additionally, by adding the average-pooled feature maps from the raw series to the U-Net encoder, which is used in [1], significantly improved learning convergence and stabilization.\n\nNote that this model is very lightweight, with the checkpoint size being only 3.5MB per model, totaling 54MB for 15 models. The training time is about 6 minutes per model for 20 epochs, and it takes about 1.5 hours for all 15 models using Nvidia RTX4090. Furthermore, the scoring time on Kaggle Notebook for the entire pipeline was approximately 20 minutes.\n\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F145f459b4db889e7a678d4417f0b43cd%2Fcmi_1st_stage_architecture.svg?generation=1704803853869284&alt=media\" width=\"480px\" />\n\n**Figure 3. The architecture of the 1st stage model**\n\n### AP-Optimized Postprocessing\n\nI made some improvements to the AP evaluation metric-optimized postprocessing that was shared in [2].\n\nIn [2], they computed the rolling sum of scores within a window of `k=2 * (tolerance_quarter_minute - 1) + 1`, whereas in this ablation study, I used rolling mean to aggregate scores of quarter points in each tolerance range. Since the total score aggregated by the rolling sum is proportional to the window size, it gives more weight to windows with greater tolerance. By using the rolling mean as the aggregation function, it's possible to mitigate the bias in weights for each tolerance.\n\n## 2nd Stage\n\n### Model\n\nI created a regression model using XGBoost[6].\n\n### Input Features\n\nI utilized the following 14 features. All are extracted solely from the 1st stage model's prediction results (`series_id`, `event`, `night_id`, `step`, `score`), without using the original series features. The importance of these features are visualized in Figure 4.\n\n- `event`\n- `rel_night_id`\n- `valid_rate_per_night`\n- `valid_rate_per_series`\n- `confidence`\n- `rank_per_night`\n- `mean_confidence_per_night`\n- `mean_confidence_per_series`\n- `norm_confidence_per_night`\n- `norm_confidence_per_series`\n- `abs_min_diff_from_HDCZA` [4]\n- `abs_min_diff_from_top_0`\n- `sum_confidence_per_night`\n- `confidence_normalized_by_mean_per_night`\n\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F485962d7022b3611992cf7d254dcfd43%2Fcmi_feature_importance_of_2nd_stage_features.png?generation=1704806006943498&alt=media\" width=\"640px\" />\n\n**Figure 4. Importance of 2nd Stage Features**\n\n### Target\n\nThe design of the label was inspired by [3]. The difference is that while [3] used top-k accuracy as the target in training phase, then applies diff of top-k accuracy as predicted score in inference phase, this ablation study regressed diff of top-k accuracy directly. Furthermore, the original implementation supplied binary labels by fixed threshold, but in this study, I used soft labels with logistic regression. The local validation results showed a slightly higher AP score with this configuration.\n\n## Ablation Study\n\nThe results of the Ablation Study are shown in Table 1.\n\nThe largest impact was observed from ablating the flag indicating whether the data was imputed or not (AP=-0.0236), presumably because the model generated many False Positives due to features indicative of spurious onset/wakeup. Note that the ablation of the flag for imputed data was achieved by providing `is_valid=1` for all series during inference, using a model that is trained *including* the `is_valid` feature. This is because I wanted to save time for training another models. Note that this settings can be slightly different to the result of the model *without* `is_valid` feature both training and inference phases.\n\nThe contributions of the AP-optimized postprocessing and the ablation of the 2nd stage model were roughly equivalent (each reducing the local AP by -0.0075 and -0.0071, respectively).\n\nThe algorithm used in the original [2] (AP Optimization with rolling summation) alone decreased AP (local AP by -0.0144), but could be somewhat restored in performance by the 2nd stage model (local AP by -0.0016). However, I couldn't observe positive gain over the baseline using `find_peak`. Thus, this ablation study failed to achieve the huge gain as reported in [2] with the 2nd stage model. This is possibly due to not feeding the original input series features to the 2nd stage models. Feeding with richer input features could improve 2nd stage models higher beyond.\n\nImportantly, as shown in this case, the impact of postprocessing which is optimized for the specific evaluation metrics *can be significant*. In tasks where AP is used as the evaluation metric for models (e.g., object detection tasks), substantial gains might be achieved through such kind of postprocessing, as used in [2] and this ablation study. Conversely, this also means evaluating solely on the AP metric might make it difficult to distinguish whether the results are evaluating the model's performance itself or an (over-)optimized outcome for the specific evaluation metrics. In the case of object detection tasks, fortunately, most literature applies only simple postprocessing, such as NMS (Non-Maximum Suppression), so the impact might not be as severe as I concerned. However, there are some examples, like DETR[5], which employ tricks such as allocating empty object query slots for predicting a second probable candidate bounding boxes to boost AP scores. When evaluating such models, careful judgment is required to determine whether the results are attributable to the model's performance itself or the results of postprocessing optimized for specific metrics.\n\n**Table 1. Results of the ablation study:**\n\n| w `is_valid` feature | w AP Optimization (Sum) | w AP Optimization (Avg) | w 2nd Stage (Weight=0.2) | w 2nd Stage (Weight=1.0) | AP Local (OOF) | LB Public | LB Private | Scoring Time (min) |\n| -------------------- | ----------------------- | ----------------------- | ------------------------ | ------------------------ | -------------- | --------- | ---------- | --------------------- |\n|                      |                         |                         |                          |                          | 0.79           |           |            |                       |\n| x                    |                         |                         |                          |                          | 0.8136         |           |            |                       |\n| x                    | x                       |                         |                          |                          | 0.7992         |           |            |                       |\n| x                    | x                       |                         | x                        |                          | 0.8009         |           |            |                       |\n| x                    | x                       |                         |                          | x                        | 0.812          |           |            |                       |\n| x                    |                         | x                       |                          |                          | 0.8211         | 0.772     | 0.833      | 22                    |\n| x                    |                         | x                       |                          | x                        | 0.8263         | 0.77      | 0.838      | 20                    |\n| x                    |                         | x                       | x                        |                          | 0.8282         | 0.777     | 0.838      | 20                    |\n\n## What Didn't Work\n\nFor the input features of the 2nd stage, I tried adding target encoding features based on the overall distribution of Ground truth, such as event timing, inspired by the idea in [1]. However, this did not improve the local validation score.\n\nRegarding the features of the 2nd stage model, I also tested patterns using features similar to those used in [3], but this slightly worsened the local AP. Additionally, while some features improved the local validation score, they worsened the LB score. This stage's model is prone to overfitting and domain shift effects, so careful design of features is necessary.\n\n## Acknowledgements\n\nI would like to express my gratitude to the hosts who organized the competition and to everyone at Kaggle management. I also extend my thanks to all the participants who shared their solutions and ideas.\n\n## Reference\n\n- [1] [14th place solution by Jack](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/460274)\n- [2] [1st place solution by shimacos, sakami, and kami](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/459715)\n- [3] [2nd place solution by K-mat](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/459627)\n- [4] https://www.kaggle.com/code/tatamikenn/sleep-hdcza-a-pure-heuristic-approach-lb-0-447\n- [5] [End-to-end object detection with Transformers](https://ai.meta.com/research/publications/end-to-end-object-detection-with-transformers/)\n- [6] https://xgboost.readthedocs.io/en/stable",
    "2593809": "## Appendix: The visualization of 2nd stage model's predictions\n\nThe below are the visualization of 1st stage scores and 2nd scores sampled from night chunks. In the general tendency, the model fails to increase confidence of lower-ranked predictions where the GT events are placed nearby. However, it seems to succeed in increasing the confidence of 1st models for higher-ranked predictions. This can be because of with the information gained from aggregated features over `series_id` or `night_id`, they can successfully decide whether and how much confidence the 2nd model should increase over these predictions.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2Feb754f608959c110eb45a1395de40f38%2Fsample_01.png?generation=1704806148833178&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F82320fe1c18d896e2817f5496fd6e745%2Fsample_02.png?generation=1704806160612952&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4910466%2F644ff610a10ee6039e4b8de00b7746e7%2Fsample_03.png?generation=1704806469987441&alt=media)"
  },
  "source": "existing_discussion",
  "complete": true,
  "competition_id": 53666,
  "competition_slug": "child-mind-institute-detect-sleep-states",
  "team_id": 11134590,
  "solution_url": "/competitions/child-mind-institute-detect-sleep-states/writeups/bilzard-ablation-study-on-publicly-shared-solution"
}