Peak-hour traffic adds 30–40 minutes to a commute — and that's not fatalism, but a challenge for AI. We develop congestion prediction systems that reduce delays by 15–25%. At the core is a hybrid of graph neural networks and event-aware transformers. The model considers road topology, data flow from 300+ sensors, and events (accidents, weather, concerts). Our clients are cities and transport operators who need not just to predict a jam but to redistribute traffic in real time. Below is how we do it: from data collection to integration with navigators and traffic lights.
The problem with classical methods is that they ignore road topology and event dynamics. For example, after a concert at a stadium, traffic redistributes non-linearly — 40% of drivers choose alternative routes. Our AI model predicts such scenarios with up to 92% accuracy on a one-hour horizon. For comparison, traditional LSTM models show MAPE of 14–18%, while our architectures based on GCN+WaveNet achieve 8–11%.
We use PyTorch and PyTorch Geometric for building graph models, and for event encoding — Temporal Fusion Transformer (TFT). Accuracy evaluation is performed on historical data broken down by day type. The result is flow speed prediction with MAPE <10% on a 30-minute horizon.
How AI improves traffic prediction accuracy
Prediction relies on four data groups:
- Sensors: induction loops (count, speed), video detectors (vehicle classification), Wavetronix/RTMS radars.
- Floating car data: aggregated GPS tracks from navigation services and taxi fleets.
- Infrastructure: road graph (OpenStreetMap), traffic light phases, pedestrian crossings.
- Events: planned (matches, concerts) and anomalous (accidents, construction, snowfall).
We combine them into a spatial-temporal model where each sensor is a graph node and roads are edges.
Why graph neural networks are more effective than LSTM
Traditional LSTMs ignore road topology. Graph convolutions (GCN) account for the fact that speed at a neighboring intersection affects the current one. Comparison of approaches:
| Model |
Spatial dependency |
Temporal dependency |
MAPE (30 min) |
Latency (inference) |
| LSTM |
No |
Yes |
14–18% |
<1 ms per node |
| GCN + LSTM |
Yes (static edges) |
Yes |
10–13% |
2–5 ms per graph |
| Graph WaveNet |
Yes (adaptive matrix) |
Yes (dilated conv) |
8–11% |
3–8 ms per graph |
Comparative analysis on city sensor data over 12 months
We use the architecture:
# TrafficGCN — hybrid of GCN and LSTM
import torch
from torch_geometric.nn import GCNConv
class TrafficGCN(nn.Module):
def __init__(self, n_nodes, in_features, hidden, out_features):
super().__init__()
self.gcn1 = GCNConv(in_features, hidden)
self.gcn2 = GCNConv(hidden, hidden)
self.lstm = nn.LSTM(hidden, hidden, batch_first=True)
self.fc = nn.Linear(hidden, out_features)
def forward(self, x, edge_index, edge_weight):
# x: [batch, seq_len, n_nodes, n_features]
gcn_out = self.gcn1(x, edge_index, edge_weight).relu()
gcn_out = self.gcn2(gcn_out, edge_index, edge_weight)
lstm_out, _ = self.lstm(gcn_out)
return self.fc(lstm_out[:, -1, :])
TrafficGCN architecture details
The model uses two graph convolutions with residual connections and an LSTM layer for temporal dynamics. Training: AdamW, lr=0.001, batch_size=32, 100 epochs. Graph size — up to 5000 nodes, 15000 edges. Accuracy evaluation is performed on a held-out set (20% of data).
Key architectures — DCRNN, Graph WaveNet, ASTGCN — differ in how they handle temporal dependencies. The choice depends on graph size and forecast horizon.
How events are taken into account
Traffic is non-linear: after a football match, peak occurs in 30–60 min; an accident reduces capacity by 40–80%; rain decreases speed by 10–20%. We add event flags as input features:
event_features = {
'stadium_match_flag': upcoming_match_within_3h,
'weather_rain_intensity': precipitation_forecast,
'roadwork_active': roadwork_on_segment,
'incident_nearby': incident_within_1km_duration,
'holiday_flag': is_holiday,
'school_day': not is_school_holiday
}
These features are fed into the model as future covariates (Temporal Fusion Transformer). Without them, accuracy on anomalous days drops by 20%.
What does AI traffic light optimization provide?
Traditional SCOOT/SCATS react to current traffic without prediction. We replace them with an RL agent: action — phase plans, state — current and predicted speeds, reward — total network delay. On a corridor of 10–20 intersections, coordination creates a 'green wave'. Result: reduction in average travel time by 10–20%. Such smart traffic lights based on RL are an example of AI transportation systems.
Informing drivers
Predictions are sent to:
- variable message signs (travel time, detours),
- push notifications in apps (navigation services),
- API for navigation services.
System metrics:
| Metric |
Value |
| MAPE of flow speed (15 min) |
<10% |
| MAPE of travel time (30 min) |
<12% |
| Incident detection latency |
<5 min |
| Reduction in average travel time |
10–25% |
A 10–25% reduction in average travel time is tangible for every driver. For a city of a million people, this yields significant savings in public costs.
Case study: deployment in a city of 2 million residents (from our practice)
For one of our clients — City N with 2 million residents — we deployed Graph WaveNet with event-aware layers. After calibration on historical data, MAPE of speed on a 30-minute horizon was 7.8% (normal days) and 10.2% (event days). The system is integrated with the local traffic management center via the NTCIP 1211 protocol. This enabled real-time congestion analysis and coordination of 500 intersections.
What is included in the development?
- Data audit: sensor availability, FCD quality, road network layout.
- Prototype model: LSTM baseline in 2–3 weeks.
- GNN + event-aware model calibrated to the city.
- Integration with traffic light controllers and navigation services.
- Documentation, operator training, warranty support.
Timeline: basic prediction — from 5–6 weeks; full system — 4–5 months. Accurate estimate after data analysis.
We guarantee accuracy: MAPE not exceeding target values on the test set. Team experience — over 5 years in ITS (Intelligent Transport Systems) and 20+ projects in traffic forecasting. Our solutions fall under AI transportation and ML transportation.
Get a consultation on your system architecture. Contact us to evaluate your project — we'll select an architecture that fits your budget and city infrastructure. Order a preliminary data audit: we'll analyze available sensors and provide an initial accuracy estimate within two weeks.
When does a time series forecasting model fail in production?
The CFO requests a quarterly sales forecast. An analyst builds SARIMA on three years of data, achieves MAPE 8.3% on the test set, and deploys. Two months later, the metric in production jumps to 23%. The root cause: the model was trained on pre‑COVID data, tested on a stable period, but production hit a promotion and supply chain disruption. Data leakage plus distribution shift—perfect notebook numbers, a broken forecast in reality. We have seen this pattern dozens of times across retail, fintech, and IoT. Our team has delivered more than 50 forecasting projects over 5+ years.
Incorrect cross-validation. Standard train_test_split for time series creates data leakage: the model sees future values during training. The correct approach is TimeSeriesSplit or walk‑forward validation with an expanding window.
Multiple seasonality. Hourly electricity consumption has three seasonalities: daily (24h), weekly (168h), yearly (8760h). SARIMA handles only one. Prophet can handle multiple but scales poorly to thousands of series.
Missing values and anomalies. A missing sensor reading is information (the sensor turned off), not NaN. Linear interpolation destroys this signal. Proper handling depends on the missingness mechanism.
Cold start. A new SKU in a 50,000‑item assortment has no history, yet a forecast is needed. Standard approaches fail; cross‑learning or feature‑based methods are required.
Why is model selection critical for your data?
Prophet (Meta) – a solid start for business data with clear seasonality and holidays. Fast setup, interpretable, built‑in outlier detection. Fails on irregular patterns and does not scale beyond ~10k series without parallelization.
Gradient boosting on features (LightGBM, XGBoost) – often underestimated. Engineer lags (t‑1, t‑7, t‑28), rolling means, day‑of‑week, holidays. The model trains on all series simultaneously, solving cold start via transfer learning. MAPE in retail often beats neural nets with proper feature engineering.
TFT (Temporal Fusion Transformer) – a transformer designed for interpretable forecasting with covariates. Built‑in variable selection, temporal attention, quantile outputs. Available in pytorch‑forecasting. Requires ~10,000+ records per series for stable training.
PatchTST – splits the series into patches (like ViT for images), capturing local patterns better than classic transformers. Excellent for long‑horizon forecasting (96–720 steps ahead).
N‑HiTS, N‑BEATS – attention‑free neural architectures, faster than TFT, competitive accuracy. N‑BEATS won the M4/M5 benchmarks for tasks without covariates.
| Method |
Covariates |
Scale (series) |
Interpretability |
Complexity |
| Prophet |
Yes (regressors) |
Up to 10k |
High |
Low |
| LightGBM + features |
Yes |
100k+ |
Medium |
Medium |
| TFT |
Yes |
1k–100k |
High |
High |
| PatchTST |
No/limited |
Any |
Low |
Medium |
| N‑HiTS |
No |
Any |
Low |
Low |
How do we deploy TFT in production?
A typical pipeline via pytorch‑forecasting:
training = TimeSeriesDataSet(
data,
time_idx="time_idx",
target="sales",
group_ids=["store", "sku"],
min_encoder_length=max_encoder_length // 2,
max_encoder_length=max_encoder_length, # 120 days
min_prediction_length=1,
max_prediction_length=max_prediction_length, # 28 days
static_categoricals=["store_type", "category"],
time_varying_known_reals=["price", "promo_flag"],
time_varying_unknown_reals=["sales"],
target_normalizer=GroupNormalizer(groups=["store", "sku"], transformation="softplus"),
)
A common mistake: the default target_normalizer (StandardScaler) breaks predictions for series with zero values (no sales on weekends). GroupNormalizer with transformation="softplus" is the correct choice for count data.
Case study: retail demand forecasting
A chain of 120 stores, 8,000 SKUs, 28‑day forecast horizon. The original system: SARIMA per series, MAPE 18.4%, retraining cycle – 6 hours. We replaced it with TFT on PyTorch + pytorch‑forecasting: a single model for all series, MAPE 11.2%, retraining – 40 minutes on an A10G. Feature importance via variable selection revealed that day_before_holiday influences more than the holiday date itself. Annual savings on inference alone exceeded $50,000.
Step‑by‑step configuration
-
Data collection and preparation. Handle missing values (mark NaN, interpolate only for technical failures), aggregate to required frequency, engineer covariates (holidays, promotions, prices).
-
Create
TimeSeriesDataSet. Set group_ids (store + SKU), time index, forecast horizon. Choose target_normalizer based on target distribution.
-
Train a baseline. Prophet or LightGBM first – to understand complexity.
-
Train TFT. Use
TemporalFusionTransformer with loss=QuantileLoss(), tune learning rate and hidden layer sizes.
-
Validate and interpret. Walk‑forward test, analyze variable selection, build attention heatmaps.
How to properly evaluate forecast quality?
RMSE alone is misleading – it over‑penalizes large values. Our standard set:
-
MAPE – interpretable, unstable near zero.
-
sMAPE – symmetric, avoids division by small numbers.
-
MASE (Mean Absolute Scaled Error) – normalized relative to a naive seasonal forecast, ideal for comparing series of different scales.
-
Pinball loss – for probabilistic forecasting, inventory management.
| Metric |
When to use |
Drawback |
| MAPE |
Business reporting, series without zeros |
Unstable for small values |
| sMAPE |
Model comparison |
Asymmetric interpretation |
| MASE |
Multi‑scale series, benchmarks |
Needs seasonal naive baseline |
| Pinball loss |
Probabilistic models |
Multiple values for different quantiles |
We guarantee a model card with these metrics on the validation set and walk‑forward results on at least 6 months of history.
What deliverables do you receive?
- Documentation of chosen architecture and hyperparameter rationale.
- Reproducible training and inference pipeline (Docker + CI/CD + Airflow/Prefect).
- Committed code with unit tests for key components.
- Team training: retraining, output interpretation, deployment of new versions.
- 3 months of post‑delivery support (consultations, bug fixes, fine‑tuning).
The model is deployed via FastAPI or Triton Inference Server. Retraining is scheduled (e.g., weekly) via Airflow with drift validation and automatic rollback if metrics deteriorate.
Process and timeline
We start with EDA: visualization, ADF test, STL decomposition, analysis of missing values and outliers. This takes 2–3 days but often reveals systemic data issues that block forecasting. Then we build a baseline (naive seasonal, Prophet), engineer features for LightGBM, and select a neural architecture if needed. Walk‑forward validation with a realistic horizon. Deployment via API with automatic retraining scheduled via Airflow or Prefect.
Timeline: MVP forecast on one data type – 3–6 weeks. Hierarchical forecasting system with automation – 2–5 months. Cost is calculated individually based on data volume, number of series, and required accuracy.
Our team consists of certified ML engineers (AWS ML Specialty, GCP Professional ML Engineer) with 5+ years on the market and over 50 completed forecasting projects. Contact us for a free analysis of your data – we will assess the task and provide initial recommendations within 1–2 days. Request a consultation to ensure your forecasts work in production, not just in a notebook.