Back to Vincent Teo's portfolio
Rapid KL Ridership Forecast screenshot 1
Featured

Engineering case study

Forecasting Rapid KL Ridership 28 Days Ahead with XGBoost

Personal project

XGBoostPythonpandasTime-series forecastingGitHub ActionsNext.js

4.2% average error on a year of unseen days; 33% less error than the usual-level baseline. Refreshed daily and retrained monthly.

A live forecast of daily passenger entries on the Rapid KL rail network, up to 28 days ahead, for the whole network, each line and each of 166 stations. An XGBoost model is refreshed every evening with the newest open data and shown on this site as an interactive chart and table.

The problem

How busy will the Rapid KL rail network be next week? Operators, businesses near stations and commuters all plan around that, and the answer changes sharply around public holidays, Ramadan and festive seasons.

Malaysia's open-data portal publishes how many trips are made between every pair of Rapid Rail stations each day (Daily Origin-Destination Ridership: Rapid Rail, data.gov.my, CC BY 4.0), from January 2023 onward and refreshed daily. This project turns that into a forecast for dates that have not happened yet.

My contribution

A personal project covering the data pipeline, the model, its evaluation, the daily forecasting job and the chart on this site.

How it works

Station entries are taken from the portal's per-station totals, then summed into 174 daily series: the whole network, 7 lines and 166 stations.

One pooled XGBoost model covers every series. It predicts how far a day will sit above or below that series' usual level for the weekday (the median of recent same weekdays, leaving out public holidays and disrupted days such as a station closure), on a log scale, so quiet and busy stations share one model and holiday effects are learned as percentages.

Every input is known on the day the forecast is made: the weekday, month and day of the month; Kuala Lumpur public holidays, the days before and after them, bridge days, Ramadan, and distance from Hari Raya and Chinese New Year; and the series' own recent history, trend and the same period a year earlier.

A scheduled GitHub Actions job runs every evening: it downloads the newest data, forecasts the next 28 days and publishes the result as a file that this site reads. A second job retrains the model on the 1st of each month and publishes it only if its forecasts stay close to the previous model's. No server has to stay running.

The evening job also checks its own work. It scores the forecasts it published earlier against the real figures, one day ahead and also 7, 14 and 28 days ahead, and shows the error, the bias and how often the real figure fell inside the range. For the next day only, the network forecast is nudged by half of the last week's median miss. Days when a single station runs far above its forecast, such as a concert, are taken out of that miss so an event is not mistaken for a change in demand.

Before publishing, the job checks the file: 28 days, no gaps or negative numbers, every forecast inside its own range, no collapse in the number of series, and data that is not stale. If a check fails nothing is published and the site keeps the last good file. A missing or damaged previous file only restarts the track record, and a retrained model is used only if it matches the current design.

Engineering decisions

The data is split by date, never at random: trained on targets up to 11 November 2025, with the design chosen on the six months before that, then tested on the following full year. The test year was meant to be used once; it was looked at again to decide not to keep one late change (below), so a rolling backtest was added as cleaner evidence.

Three baselines that need no model are reported beside it: "same weekday last week", "same weekday a year earlier" and the usual level itself. A model that cannot beat them is not worth running.

Hourly forecasts were considered and dropped: only daily figures are published for Rapid Rail, and inventing an hourly pattern would not be honest.

The numbers are station entries, where each journey is counted once at the station it starts from. They are lower than the operator's official line ridership, which also counts passengers transferring onto a line, so the page says "entries" and does not claim to forecast the official figures.

The forecast range on the chart comes from two extra models that predict the low and high ends directly (quantile regression), so it widens around holidays and narrows on ordinary days. On their own those models were overconfident: only 59% of network outcomes fell inside a range meant to hold 80%. The range is therefore widened by the amount needed on held-out data (conformal calibration), separately for near and far forecasts, which brought it to 77% to 79%.

Several ideas were tested on earlier data and dropped because they did not help consistently: school-holiday dates, holiday type, and extra weight on holiday days. Same-day rainfall cut the network error by about 5%, but only when the true rainfall was known in advance, so it is left out until it is tested with real weather forecasts.

After a concert at Bukit Jalil in November 2026 pushed the network 6% above forecast on two days, two fixes were tried: capping how far a past day may sit from usual when it is used as an input, and leaving station spikes out of training. Both helped slightly on the two validation periods, but on the test year they were neutral overall and worse the day after a spike at Bukit Jalil, because events there run on consecutive nights and yesterday's spike really does predict today's. They are switched off.

The next-day nudge was handled differently: its weight was chosen on the validation period only, for each horizon from 1 to 10 days, and kept only where it cut the error by at least 2%. Only the next day qualified. On the test year it cut next-day network error from 3.7% to 3.4%, and it did nothing for lines or stations, so it is used for the network only.

Evidence and evaluation

Tested on 12 November 2025 to 11 November 2026 (about 520,000 forecasts, made 1 to 28 days ahead), as the error in percent of ridership:

- Whole network: model 4.2%, usual level 6.3%, same weekday last week 8.9%, same weekday last year 9.3% - Lines: model 4.5%, usual level 6.8%, last week 9.4%, last year 9.6% - Stations: model 6.7%, usual level 9.0%, last week 11.7%, last year 12.9%

That is 33% less error than the usual-level baseline for the network, and 26% less for single stations.

Most of the gain comes from holidays. Around public holidays, Chinese New Year and Hari Raya the network error is 9.8% against 28.1% for the usual level, and resampling whole weeks puts the 95% range of that gain at 54% to 76%. On ordinary days the network error is 3.6% against 3.8%, and the 95% range for that gain runs from -9% to +18%, so for the network alone it cannot be told apart from the usual level. For lines (+1% to +19%) and stations (+2% to +14%) the gain is small but real.

A rolling backtest trained the model only on days before each of five cut-off dates and scored the following three months. It beat the usual level in all five, with network error between 3.2% and 6.2% (average 4.0%). The weakest period, February to May 2026 (Ramadan, Hari Raya and Chinese New Year), was worse than the usual level on ordinary days: 4.3% against 2.5%.

Error grows slowly with distance: 3.7% one day ahead and 4.8% at 28 days. The 80% range held the real figure 77% of the time for the network and 79% for lines and stations; it is weakest in holiday periods for lines and stations (72% and 74%). The site keeps each published forecast and compares it with the real figure once that is released, at 1, 7, 14 and 28 days ahead, so the track record is public.

Limitations and next steps

There is no hourly forecast, because hourly data is not published.

Holiday periods are still about three times harder than ordinary days, and Islamic holiday dates in future years are estimates until they are officially announced. Ramadan and Hari Raya are learned from only three occurrences, which is why the rolling backtest was weakest around them.

Weather, service disruptions, fare changes and one-off events are not modelled. Events matter locally: in the test year 181 station-days ran at more than 1.8 times their forecast, mostly at Bukit Jalil, Glenmarie, Merdeka, Persiaran KLCC and Maharajalela. A concert at Bukit Jalil added about 16,000 entries on each of 19 and 20 November 2026. The forecast cannot know about an event in advance; the track record names such days afterwards.

A brand-new station or line has little history; the LRT Shah Alam Line only has data from August 2026, so its forecasts deserve less trust.

Next steps are a calendar of large events near stations, a better treatment of Ramadan, testing rainfall using archived weather forecasts, and reporting the live track record by station as well as for the network.

The story behind it

Analytics cookies

I'd like to use Google Analytics to see which pages are useful. It sets cookies and is off unless you accept. Privacy policy