Swiss public transport delays at scale
One year of real Swiss transit data for the canton of Vaud, enriched with weather and reference data. We built a Spark pipeline that scales, tuned its performance, and used it to predict late trips and profile every stop in the network.
At a glance
The data is the official "actual data" feed of Swiss public transport: one row for every stop served by every train, bus, tram, metro or boat, with scheduled and measured times. Over 92% of records carry real measured times, which makes it a reliable source for punctuality analysis.
From daily CSV dumps to analysis-ready Parquet
Feature engineering in Scala
Join with the official stop registry to keep only stops in Vaud, normalise inconsistent transport-type labels, parse mixed timestamp formats and derive arrival and departure delays.
Enrichment
Daily weather (rain, snow, temperature, wind gusts) from the Open-Meteo archive, joined on the operating day.
Columnar storage
Output written to Parquet, partitioned by year and month, so queries only read the columns and months they need.
Same code, two environments
Zeppelin notebooks that run unchanged in a local Docker setup and on a Google Cloud Dataproc cluster.
Five questions, answered with Spark SQL
Who runs the network?
Share of trips operated by SBB vs. local Vaud companies, by transport mode.
Does weather cause cancellations?
Cancellation rate per weather bucket: dry, rain, heavy rain, snow, frost.
Which mode is most reliable?
Late and cancelled rates for train, bus, tram, metro and boat.
When is the network most stressed?
Delay distribution across peak and off-peak time slots.
Do delays snowball?
First-stop vs. terminus delay per trip: amplifying, stable or recovering.
Profiling and tuning with the Spark UI
The Spark UI showed that inferSchema was forcing a full eager scan of the CSV. An explicit schema made loading lazy, and caching the joined data with persist() removed repeated work.
We then scaled the input from 10% to 100%, locally and on an 8-vCPU Dataproc cluster in Zurich. Both curves are close to linear, so the pipeline behaves predictably as data grows. The cluster was slower than a single machine, though. At 1.4 GB of Parquet, the cloud storage latency costs more than the parallelism brings, and our pipeline has almost no shuffle to distribute.
About 100 s of fixed overhead, plus a part that grows linearly with the data.
Predicting late trips
Will a trip arrive more than 3 minutes late? The model is a logistic-regression Spark MLlib pipeline trained on ~250,000 trips. Features are line, operator, transport mode, cyclical encodings of hour and weekday, and daily weather.
Profiling every stop
Six features per stop, computed in a single Spark SQL query over the full year: traffic, peak concentration, bus share, seasonality, average delay and dwell time. K-Means with k = 4 (silhouette 0.57, chosen by elbow and silhouette scan) finds four clearly different kinds of stops.
Saturated urban hubs
44 stops · 1%- per day
- 756
- bus share
- 93%
- avg delay
- 75 s
Bel-Air, Chauderon, St-François, Lausanne gare…
Peri-urban bus stops
2,378 stops · 68%- per day
- 109
- bus share
- 100%
- avg delay
- 94 s
The backbone of the network, and the least punctual.
Quiet seasonal stops
749 stops · 21%- per day
- 24
- seasonality
- 0.76
- avg delay
- 47 s
Low traffic that varies strongly across the year.
Rail connection nodes
332 stops · 9%- per day
- 84
- bus share
- 1%
- dwell
- 21 s
Train stations where vehicles wait for connections.
Tools & techniques
- Processing
- Machine learning
- Infrastructure
- Performance