All projects Big data · Spark · Scala

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.

Context
MSc Big Data Analytics, HES-SO
Team
3 students (me + 2 teammates)
Period
Spring 2026
Infrastructure
Local Docker · Google Cloud Dataproc
Overview

At a glance

73M
stop events, May 2025 to April 2026
14×
smaller: ~20 GB of CSV → 1.4 GB of Parquet
−41%
runtime after Spark tuning
3,503
stops profiled by clustering

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.

Pipeline

From daily CSV dumps to analysis-ready Parquet

Ingestdaily CSVs
Enrichstops · weather
Storepartitioned Parquet
AnalyseSpark SQL
ModelMLlib

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.

Questions

Five questions, answered with Spark SQL

Q1

Who runs the network?

Share of trips operated by SBB vs. local Vaud companies, by transport mode.

Q2

Does weather cause cancellations?

Cancellation rate per weather bucket: dry, rain, heavy rain, snow, frost.

Q3

Which mode is most reliable?

Late and cancelled rates for train, bus, tram, metro and boat.

Q4

When is the network most stressed?

Delay distribution across peak and off-peak time slots.

Q5

Do delays snowball?

First-stop vs. terminus delay per trip: amplifying, stable or recovering.

Performance

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.

Full feature-engineering notebook local run, wall-clock time
before
8 min 51 s
after
5 min 14 s · −41%

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.

Scaling with input size
localDataproc cluster
10%
106 s
168 s
25%
125 s
176 s
50%
154 s
206 s
100%
183 s
256 s

About 100 s of fixed overhead, plus a part that grows linearly with the data.

Machine learning

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.

Confusion matrix, 49,717 test trips AUC 0.755 · accuracy 68.4% · baseline 56%
predicted on timepredicted late on time
14,248correct
7,369false alarm
late
8,358missed
19,742correct

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.

Stack

Tools & techniques

Processing
  • Apache Spark
  • Scala
  • Spark SQL
  • Parquet
Machine learning
  • Spark MLlib
  • Logistic regression
  • K-Means
  • StandardScaler
Infrastructure
  • Docker
  • Zeppelin
  • Google Cloud Dataproc
  • GCS
Performance
  • Spark UI profiling
  • Explicit schemas
  • persist()
  • Scaling tests
Next project

Smart cat bowl