How to use SMOTE for sequential data
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Using vanilla SMOTE on sequential data is usually risky because SMOTE assumes feature vectors are independent points in space, while sequences have order and temporal structure. The safe answer is not "apply SMOTE directly to the raw sequence", but to decide whether each sequence window is truly an independent sample or whether you need sequence-aware balancing strategies instead.
Why Raw SMOTE Is a Problem for Sequences
SMOTE creates synthetic minority examples by interpolating between nearby samples. That can make sense for ordinary tabular vectors, but it can distort sequential data in several ways:
- temporal order may be blurred
- unrealistic transitions may be created
- future information can leak through bad window construction
- sequence semantics may no longer match the label
For example, interpolating two sensor sequences point-by-point may produce a shape that no real system would ever generate.
When SMOTE Can Still Be Acceptable
SMOTE can be reasonable if you have already transformed each sequence into an independent fixed-length example and the downstream model treats each window as one labeled sample.
For example, suppose you classify short windows of a signal after converting each window into summary features:
Here, SMOTE operates on feature vectors that already summarize the sequence. That is much safer than interpolating the raw time steps directly.
A Better First Option: Class Weights
If you are training an LSTM, GRU, or transformer on raw sequences, class weighting is often a better first choice than synthetic oversampling.
This keeps the original sequential structure intact while still telling the loss function to care more about the minority class.
Windowing Must Respect Time Order
If you create sliding windows from a time series, do that before any balancing logic and be careful not to mix windows from future data into earlier training folds.
Good order:
- split data by time or sequence identity
- build windows
- balance only the training set
- leave validation and test sets untouched
If you oversample before the split, you can leak information between train and validation sets and get unrealistic scores.
Sequence-Aware Alternatives
Depending on the domain, safer alternatives include:
- class weighting
- focal loss
- undersampling the majority class
- domain-specific sequence augmentation
- generating synthetic sequences with a model built for sequence data
For example, in NLP you might use token-level augmentation rules. In sensor data you might use time warping, magnitude scaling, or jitter that respects the problem domain better than linear interpolation between full sequences.
If You Must Use SMOTE, Flatten Carefully
Some practitioners flatten fixed-length windows and run SMOTE on the flattened vectors:
This can work mechanically, but it is only defensible if each fixed window is already treated as an independent example and the synthetic interpolation still makes sense in the domain. That is a much narrower use case than many tutorials suggest.
Common Pitfalls
The biggest mistake is applying vanilla SMOTE directly to raw sequential observations and assuming the synthetic outputs are still realistic time-series samples.
Another common issue is balancing before the train-validation split, which leaks information and inflates performance metrics.
People also forget that class imbalance can often be handled more safely with class weights, focal loss, or careful sampling rather than synthetic interpolation.
Finally, do not evaluate balancing methods only by class counts. The synthetic data has to preserve the temporal meaning of the task, not just produce equal label frequencies.
Summary
- Vanilla SMOTE is usually not the first choice for raw sequential data.
- It can be acceptable on sequence-derived feature vectors when each sample is already independent.
- For raw sequence models, class weighting and sequence-aware augmentation are usually safer.
- Build windows and split data before applying any balancing step.
- Only use flattened-window SMOTE if the domain supports that interpretation and validation confirms it helps.
Related reading
- How to use spaCy to create a new entity and learn only from keyword list
- How to use spacy train to add entities to an existing custom NER model? Spacy v3.0
- How to use stop_gradient in Tensorflow
- How to use TensorBoard in a Docker container on Windows
- How to use Tensorflow addons' metrics correctly in functional API?
- How to use Tensorflow dataset API with training and validation sets
- How to use tensorflow debugging tool tfdbg on tf.estimator in Tensorflow?
- How to use tensorflow feature_columns as input to a keras model
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.