TWOpen to Opportunities
Open to Opportunities
Let's Talktehanwijeratne7@gmail.com
← All projects

Data science · Python, SQL Server and Streamlit

TransitIQ

When, where and under what conditions does the Toronto Transit Commission log the most disruption, and how long does it last? I took 22 months of real bus, streetcar and subway delay logs, joined them with daily weather, and worked through to a six-page dashboard, being clear about what this kind of data can and can't support.

TransitIQ dashboard, Executive Overview page: headline figures for incidents per day, delay-minutes, severe share and P90 delay, a monthly trend by mode and six key findings.
Incidents over 669 days, about 282 a day
188,939
Bus incidents on heavy-snow days (95% CI 1.48–2.24)
1.82×
Less forecast error than the best simple rule
19%
Data
TTC bus, streetcar and subway delay data, City of Toronto Open Data (opens in a new tab)
Weather
Daily climate data for Toronto Pearson, Environment and Climate Change Canada
Period
1 January 2025 to 31 October 2026
Tools
  • Python
  • pandas
  • statsmodels
  • scikit-learn
  • SQL Server
  • Streamlit
  • Plotly
  • pytest

What I found

  1. Heavy snow, many more bus incidents

    On days with 10 cm or more of snow, buses logged 1.82 times as many incidents as on similar days, after allowing for month, weekday and holidays. The result held in both winters and under nine sensitivity checks, but it rests on only eight storm days.

  2. Night-time bus incidents last longer

    Bus incidents between 01:00 and 06:00 had 2.61 times the odds of lasting 30 minutes or more, after adjusting for cause, route type and day type. Rush-hour incidents were not longer than others.

  3. Frequent and severe are different routes

    Busy routes such as 52 Lawrence West log incidents almost every day, but most are short. Routes such as 109 Ranee and 59 Maple Leaf log few, but many of them last over 30 minutes. Frequency rankings were very stable from 2025 to 2026 (rank correlation 0.94); extreme delays were not (0.34).

  4. Diversions dominate the delay totals

    They are 7.3% of bus records but 41.5% of bus delay-minutes, because a diversion's "delay" is how long the route was diverted. I report the headline figures with and without them.

  5. Recording habits shape the numbers

    72.8% of bus incidents of 30 minutes or more are logged as exactly 30. Ranking routes on "30 or more" would have ranked them on data-entry habits, so route severity uses "longer than 30" instead.

The dashboard

Four of the six Streamlit pages. Every number is labelled as observed, a model estimate or hypothetical arithmetic. Select one to see it full size.

TransitIQ Executive Overview page: 282.4 incidents a day, 4,499 delay-minutes a day, 8.7% severe incidents and a 30-minute P90 delay, a monthly trend chart for bus, streetcar and subway, and a list of six key findings with evidence labels.
Executive Overview: headline figures, monthly trend by mode and six key findings
TransitIQ Temporal page: incidents per day on weekdays, weekends and holidays, an hour by weekday heatmap, and a bar chart where 18.1% of overnight bus incidents last 30 minutes or more against 5 to 7% at other times.
Temporal Intelligence: hour by weekday pattern and bus severity by time of day
TransitIQ Weather page: daily incidents by snowfall band for each mode, rising sharply on heavy-snow days, the largest cause groups, and a chart of incidence rate ratios with 95% intervals for snow, rain and cold by mode.
Weather & External Causes: incidents by snowfall band and model-adjusted weather effects
TransitIQ Scenario Explorer: a heavy-snow weekday is estimated at about 162 extra bus incidents (95% range 125 to 205), with intervals that widen as uncertainty sources are added, and the eight observed storm days compared with the model.
Scenario Explorer: heavy snow and bus incidents, with each source of uncertainty

Forecasting

The task was to forecast tomorrow's incident count. The model was chosen on 2025 data with a rule fixed in advance (the simplest model within 5% of the best), then tested once on January to October 2026.

SeriesSelected modelTest error (MAE)Best simple ruleVerdict
NetworkNegative binomial27.934.6About 19% lower error
BusNegative binomial24.128.4About 15% lower error
StreetcarSame weekday, last 4 weeks7.7—The model was only marginally better, so the rule stayed
SubwayNegative binomial11.112.1Not clearly better than a good simple rule

How I did it

  1. Checked the first dataset, then dropped it

    I started with a Kaggle transport-delay dataset. Its columns looked randomly generated, departure and arrival delays were uncorrelated (r = −0.007), and a random forest only matched always guessing "delayed". I documented the checks and switched to the real TTC data.

  2. Flagged instead of deleting

    The cleaning pipeline stacks three incident files, removes 396 duplicates, rebuilds the weekday from the date and maps about 1,280 subway location labels to 77 stations. Diversions, severe delays and suspicious rows are flagged, so each analysis decides what to include.

  3. Effect sizes, not just p-values

    With 189,000 rows almost everything is "significant". Delay lengths were compared with Kruskal–Wallis and Mann–Whitney tests and Cliff's delta; daily counts with negative binomial regression and autocorrelation-robust errors.

  4. A proper database

    A SQL Server star schema with 9 foreign keys, 23 check constraints and 18 indexes, nine KPI views and ten analytical queries using window functions, CTEs, PERCENTILE_CONT and PIVOT. 46 validation checks compare it with the Parquet files, and all pass.

  5. Two measures per route, not one score

    Each route gets a frequency and a severity measure with 95% confidence intervals. Any single weighted score would be arbitrary and hide whether a route is often a bit late or rarely very late.

  6. Tested the ranges against the next year

    Route ranges built from 2025 caught only 64% of bus months in 2026 at the 80% level, and a heat model failed rules set in advance. Both are shown as observed history in the dashboard, not as predictions.

Limitations

  • No ridership or trip counts, so nothing is a rate per trip or per passenger, and there is no on-time performance.
  • The log only contains incidents the TTC chose to record.
  • One weather station, measured daily, stands in for the whole city.
  • Weather and time-of-day results are associations, not proof of cause.
  • Only 8 heavy-snow days and 20 days at 32 °C or above.
  • Delays are rounded, some cause codes are catch-alls, and bus and streetcar location text is inconsistent.
  • The forecasts were trained on one year, lag behind level changes and underestimate record storms.

Certificate viewer

Send an email

Choose your email app or a webmail service.

tehanwijeratne7@gmail.com

If your email app does not open, choose Gmail or Outlook.