Winning Kaggle the Reproducible Way

Chapter 58

Sensor Embeddings and Augmentation

A left-right swap is valid only when the label means the same thing after the swap, and assessment subjects stay unseen.

A mirror transform doubles the training windows, but it also changes what a handed label means. One demonstration measures a wrist-sensor classifier with no augmentation, a swap that relabels waving hands, and a swap that keeps the labels, on people never seen in training.

Every example is constructed for teaching. Its numbers come from running the chapter activity's code, not from a competition result.

Demonstration 1 of 1

Left-right swap augmentation on unseen subjects, by how many people recorded a left-hand wave

When does a left-right swap help a wearable activity classifier, and what does it cost when the label is not updated with the swap?

Right-hand waves look like left-hand waves after the swap, so the relabelled swap turns the abundant class into examples of the rare one: it matters most when few people recorded the left wave, and does little when many did. Keeping the original label teaches the model that left-handed waving is a right-hand wave, which makes it far worse than no augmentation whenever any left-hand waves were recorded (with none, there is nothing to spoil). A window-level cross-validation estimate leaks each person's style and a split among the training people cannot see a class that none of them recorded; with a single left-wave recorder, a person-level split can also land far from the unseen-people score.

Equation: the swapped window x tilde at time t, sensor s and axis a equals sigma a times x at time t, the partner sensor pi of s, axis a; the new label y tilde equals m of y

Scroll sideways for the whole equation

A window has shape (time, sensors, 3). The swap S exchanges the sensor axis and negates the lateral axis, and the label map m sends wave_right to wave_left, wave_left to wave_right and leaves rest and walk fixed. Macro F1 is the mean of the per-class F1 scores.

Predict first. If nobody in the training set recorded the left-hand wave, what macro F1 does the relabelled swap reach on unseen people, against no augmentation?

Your prediction

Choose an example

Scroll sideways for the whole figure

Figure: Left-right swap augmentation on unseen subjects, by how many people recorded a left-hand wave. Left: macro F1 on unseen people with 1 of 12 training people recording the left wave: no augmentation 0.900, relabelled swap 0.966, label-keeping swap 0.651. Right: window-level CV 0.987, person-level CV 0.716 and unseen-people score 0.900 for the unaugmented model.
Training people who recorded the left-hand wave (of 12): 1
Constructed example: six seeded cohorts of synthetic wrist-sensor recordings and a random forest, measured by the chapter activity.

Calculated values

No augmentation
0.900
Swap, relabelled
0.966
Swap, label kept
0.651
Left-wave F1, relabelled swap
0.962
Window-level CV (no augmentation)
0.987

When 1 of 12 training people recorded the left-hand wave, the model with no augmentation scores a macro F1 of 0.900 on unseen people and the relabelled swap 0.966, so 0.966 - 0.900 = 0.066 is the gain (left-wave F1 0.799 to 0.962). The swap that keeps the label scores 0.651, 0.900 - 0.651 = 0.249 below no augmentation. Window-level cross-validation on the training people reports 0.987 and person-level 0.716, against 0.900 on unseen people.

Worked steps

  1. Gain from the relabelled swap: 0.966 - 0.900 = +0.066.
  2. Cost of keeping the label: 0.651 - 0.900 = -0.249.
  3. Left-wave F1 with the relabelled swap: 0.962, without augmentation 0.799.
  4. Window-level CV minus unseen people: 0.987 - 0.900 = +0.087.

Use the idea

Apply a mirror augmentation only where the label is invariant or is updated with the geometry, test it by subject-held-out score with and without it, and split by person before cutting windows.

Where the conclusion applies

Constructed signals in which the left wave is the exact mirror of the right wave, so the relabelled swap is valid by design; a real non-dominant hand can differ and the gain would then be smaller. Gradient-boosted trees or a neural model on raw windows would give different absolute scores. The classes separate by amplitude and spectrum, so the axis flip itself matters little in this generator; it is kept because it is the correct geometry for mirrored units. Twelve training people and six cohorts give the means.

Check your understanding: With all 12 people recording the left wave the relabelled swap gains almost nothing, and the label-keeping swap loses a lot. Why do the two differ so much?
When both hands were recorded, the relabelled swap only adds near-copies of what the model already has, so it gains little (0.956 to 0.959). The swap that keeps the label adds a mirrored copy of every window, and the copies of right-hand waves look like left-hand waves but carry the right-hand label. That harm barely shrinks as real left-hand data grows (0.249 below no augmentation with 1 person, 0.208 with all 12, where the macro F1 is 0.748), so a transform must be checked for what it does to the labels, not only for how much data it adds.

Chapter 58 source: section "Keep Assessment Subjects Independent".