0
0
ML Pythonml~12 mins

Stationarity and differencing in ML Python - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Stationarity and differencing

This pipeline shows how we prepare time series data by checking if it is stationary and then use differencing to make it stationary. Stationary data means its patterns do not change over time, which helps models learn better.

Data Flow - 4 Stages
1Raw time series data
1000 time points x 1 featureCollect original time series values1000 time points x 1 feature
[100, 102, 105, 107, 110, ...]
2Stationarity check
1000 time points x 1 featurePerform Augmented Dickey-Fuller test to check stationarity1000 time points x 1 feature + stationarity result
p-value=0.3 (non-stationary)
3Differencing
1000 time points x 1 featureSubtract previous value from current to remove trend999 time points x 1 feature
[2, 3, 2, 3, ...] (differences of original series)
4Stationarity re-check
999 time points x 1 featurePerform Augmented Dickey-Fuller test again999 time points x 1 feature + stationarity result
p-value=0.01 (stationary)
Training Trace - Epoch by Epoch

Loss
0.5 |****
0.4 |****
0.3 |****
0.2 |****
     1  2  3  4  5 Epochs
EpochLoss ↓Accuracy ↑Observation
10.450.60Model starts learning with non-stationary data, loss is moderate.
20.380.68Loss decreases as model adapts, accuracy improves.
30.300.75Better learning after differencing, loss drops further.
40.250.80Model converges well on stationary data.
50.220.83Training stabilizes with low loss and high accuracy.
Prediction Trace - 4 Layers
Layer 1: Input raw time series value
Layer 2: Differencing operation
Layer 3: Model prediction on differenced data
Layer 4: Inverse differencing
Model Quiz - 3 Questions
Test your understanding
Why do we perform differencing on time series data?
ATo add noise to the data
BTo increase the number of data points
CTo make the data stationary by removing trends
DTo change the data format to categorical
Key Insight
Making time series data stationary by differencing helps models learn patterns better, leading to lower loss and higher accuracy during training.