Sequence data is the broad category. Time series is one of its most important engineering forms because events are indexed by real time, sampling intervals matter, and forecasting mistakes can have operational consequences.
RNNs became popular in time-dependent tasks because they can consume measurements step by step and maintain a running state. This lecture shows how sequential modeling applies to demand prediction, capacity planning, anomaly detection, and control pipelines, while also clarifying why time-aware validation is essential.
Learning Objectives
By the end of this lesson, students should be able to:
- Define time series data and explain how it differs from generic sequence data.
- Identify forecasting, classification, and anomaly detection tasks on temporal signals.
- Construct sliding windows for RNN-based time series modeling.
- Describe common tensor shapes for univariate and multivariate temporal batches.
- Recognize temporal leakage and evaluation mistakes unique to forecasting.
- Build a small PyTorch RNN for next-step prediction.
A time series is a sequence of observations indexed by time, where each measurement is associated with a temporal position such as a timestamp or fixed interval.
What Makes Time Series Different?
A time series has all the properties of a sequence, but it adds temporal direction and operational causality. The future cannot influence the past. That sounds obvious, but many modeling mistakes come from accidentally violating that rule during feature construction or data splitting.
Time series also introduces domain concepts such as trend, seasonality, lag, drift, and irregular sampling. Even when using neural networks, those concepts still matter because they shape what the model must remember.
| Pattern | Description | Example |
|---|---|---|
| Trend | Long-term upward or downward direction | Growing energy demand |
| Seasonality | Repeating cycle | Daily traffic peaks |
| Lag dependence | Past values affect current values | Sensor inertia |
| Drift | Statistics change over time | Machine wear |
Common Time Series Tasks
Forecasting
- Predict one or more future values.
- Often uses sliding windows.
- Example: next-hour demand.
Classification
- Assign a label to a whole series.
- Example: normal vs faulty machine cycle.
- Final hidden state is often useful.
Anomaly Detection
- Flag unusual temporal behavior.
- Can use errors, thresholds, or labels.
- Example: sudden equipment spike.
Sliding Window Construction
Most neural time series pipelines convert a long signal into many supervised training samples. A window of the last T steps becomes the input, and one future step or horizon becomes the target.
Select past values t-T through t-1.
Use them to estimate t or a future horizon.
Move one step forward and repeat.
Train many windows in parallel.
PyTorch Example: Next-Step Forecasting
The following model consumes a window of univariate values and predicts the next value. This is not production forecasting code, but it captures the core sequence mechanics clearly.
Understanding Temporal Shapes
| Setting | Typical shape | Meaning |
|---|---|---|
| Univariate window batch | (B, T, 1) | One value per time step |
| Multivariate window batch | (B, T, F) | F features per time step |
| One-step target | (B, 1) | Forecast a single next value |
| Per-step labels | (B, T, C) | Classify each position |
Evaluation Must Respect Time
In standard supervised learning, random train/validation splits are common. In time series, they are often wrong. If the validation set contains earlier examples than the training set, or if future statistics leak backward into preprocessing, you get an unrealistically optimistic estimate.
Good Practice
- Split by time, not random shuffle.
- Fit scalers on training data only.
- Use rolling or walk-forward validation.
Failure Modes
- Future leakage during normalization.
- Using target-derived features.
- Ignoring regime changes and drift.
Many beginners randomize individual time points before training. That destroys the very structure the model is meant to learn. Shuffle windows across samples if appropriate, but do not scramble the order inside each window.
“Neural networks remove the need for temporal reasoning.” In reality, neural models still depend heavily on correct windowing, leakage control, normalization strategy, and evaluation design.
Bridge to Hidden State and Memory
In forecasting and temporal classification, the network must decide what to retain from the recent past. That is exactly the role of the hidden state. Once the sequence definition is clear, the next question becomes: what information can the model actually carry forward?
Later in the curriculum, when Volume 09 moves into text sequences such as tokenization, the same principle returns: current meaning depends on earlier context.
Knowledge Check
- Short Answer: What makes a time series more specific than a generic sequence? Answer: It is explicitly indexed by time.
- True/False: Random train/validation splitting is always safe for forecasting. Answer: False.
- Multiple Choice: Which pattern means repeating cycles? (a) drift, (b) seasonality, (c) padding. Answer: (b).
- Short Answer: What is a sliding window in time series modeling? Answer: A fixed-length chunk of past observations used to predict a future value or horizon.
- True/False: All time series tasks are forecasting tasks. Answer: False.
- Multiple Choice: A univariate batch for an RNN is commonly shaped as: (a)
(B, T, 1), (b)(1, B, T), (c)(T, 1, B). Answer: (a). - Short Answer: Name one common evaluation practice for time series. Answer: Walk-forward validation or chronological train/validation splits.
- True/False: Shuffling the order of values inside each window preserves temporal meaning. Answer: False.
- Multiple Choice: Which next lecture explains the model memory that carries temporal context? (a) Hidden State, (b) Pooling, (c) Quantization. Answer: (a).
- Short Answer: Why is leakage especially serious in time series? Answer: Because using future information creates unrealistically strong validation results that cannot exist in deployment.
Key Takeaways
- Time series is a time-indexed subtype of sequence data with strong causality constraints.
- Neural forecasting usually relies on sliding windows and careful tensor shaping.
- Temporal leakage is one of the biggest practical risks in evaluation.
- RNNs can model forecasting, classification, and anomaly detection on sequential signals.
- Next, Hidden State explains how recurrent models carry memory forward.
Hands-on idea: Have students convert one long CSV column into overlapping windows and targets, then print the resulting tensor shapes before training.
Discussion prompt: Ask why a validation score can become misleading if a scaler is fitted on the full dataset instead of training data only.
Recap: Time series adds strict temporal direction, leakage risks, and forecasting structure to the broader sequence modeling story. Continue with Hidden State.