Prepare sequential data
Collect or simulate aligned timestamps, handle missing values, normalise scale and create fixed-length windows or subsequences for comparison.
Compute dynamic time warping. Compare sequence alignments.
Dynamic time warping (DTW) is a sequence-alignment technique that measures similarity between time series by allowing non-linear warping along the time axis. It is useful for matching patterns that are stretched or compressed in time, and is commonly applied to sensor streams, speech and activity sequences. Practical issues include length normalisation, scaling, boundary constraints (Sakoe–Chiba band), and evaluating alignment quality.
Learning concept · Not a validated service
Dynamic time warping (DTW) is a sequence-alignment technique that measures similarity between time series by allowing non-linear warping along the time axis. It is useful for matching patterns that are stretched or compressed in time, and is commonly applied to sensor streams, speech and activity sequences. Practical issues include length normalisation, scaling, boundary constraints (Sakoe–Chiba band), and evaluating alignment quality.
A proposed application: use DTW to find historical sensor traces that match a current anomalous pattern so engineers can inspect likely causes. This extension would compute DTW distances between sequences and surface the best matches; the supplied starter does not provide that functionality.
Collect or simulate aligned timestamps, handle missing values, normalise scale and create fixed-length windows or subsequences for comparison.
Implement or use a DTW routine (e.g. fastdtw, dtaidistance) to compute pairwise alignment costs and optionally return the warping path.
Apply DTW distances to nearest-neighbour retrieval, clustering of similar sequences, or template-based anomaly detection and rank matches for inspection.
Measure retrieval precision at K, inspect warping paths on examples, and test robustness to noise and time-scaling.
The supplied starter generates a synthetic daily time series with trend, seasonality and noise; creates lag and rolling features; trains a RandomForestRegressor on those features; and prints MAE and a small forecast table. It does not compute dynamic time warping distances or perform any sequence-alignment operations.
series = series.dropna()
feature_cols = ["lag_1", "lag_7", "lag_14", "rolling_7"]
train = series.iloc[:-30]
test = series.iloc[-30:]
model = RandomForestRegressor(n_estimators=300, random_state=42)
model.fit(train[feature_cols], train["value"])
forecast = model.predict(test[feature_cols])
print(PROJECT_NAME)
print("MAE:", round(mean_absolute_error(test["value"], forecast), 3))
print(pd.DataFrame({"date": test["date"], "actual": test["value"], "forecast": forecast}).head())The starter code never implements DTW: it constructs lag and rolling features, fits a RandomForestRegressor and predicts values. There is no DTW distance computation, warping path, or use of alignment constraints.
Proposed extension: compute DTW distances between a query subsequence and a library of historical subsequences, then present the top matches and their warping paths to a human analyst for root-cause inspection.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.