Engineering notes
I built a forecast for how crowded the LRT and MRT will be
How I used Malaysia's open ridership data and XGBoost to forecast Rapid KL passenger numbers 28 days ahead, what worked, what did not, and how it updates itself every night.
By Vincent Teo · Updated
Why I wanted this
I don't drive much. Work, class, shopping, meeting friends: most of it happens by LRT or MRT, and with a monthly pass it is cheaper and honestly less stressful than sitting in a jam.
The one thing that ruins it is a packed train. A concert night, the week before Raya, a rainy evening when everybody gives up on their motorbike. Some days you tap in and regret it straight away. So the question I wanted answered was simple: which day is the better day to go out?
The idea came from a group assignment. My teammates and I predicted road traffic in Victoria, Australia, from SCATS sensor data, using XGBoost, Random Forest and a bit of reinforcement learning. I enjoyed that more than I expected. The problem was that it only scored itself on days that had already happened, in a city I have never been to. I wanted one that says something about next week, here.
The data, and the first disappointment
Malaysia publishes this, which surprised me. On data.gov.my you can download how many trips were made between every pair of Rapid Rail stations, every day since January 2023, and it is refreshed daily.
I wanted an hourly forecast, because "is 6pm worse than 8pm" is the question a commuter actually has. That data is not published. Only daily totals are, and I was not going to invent an hourly pattern and pretend it was real. So the forecast is daily. I do plan to ask for hourly figures, and if they ever appear this gets a lot more useful.
From those files I built 174 series: the whole network, the 7 lines, and 166 stations. One note if you compare with official numbers: I count each journey once, at the station where it starts. Prasarana's line figures also count people changing lines, so theirs are higher.
The trick: don't predict the number
A normal weekday on the network is around 700,000 entries. A Sunday is closer to 400,000. If you ask a model to predict those raw numbers, it spends most of its effort relearning that Sundays are quiet.
So I gave it an easier job. For every series I work out the usual level for that weekday from the recent weeks, skipping public holidays and odd days like a station closure. The model only predicts how far above or below usual a day will be, as a percentage. That way a small station and KLCC can share one model, and "Raya week is much quieter than usual" is something it can learn once and apply everywhere.
What it gets to look at is only what you would know on the day you make the forecast: the weekday and month, public holidays and the days around them, Ramadan, how far away Raya and Chinese New Year are, and how that series has been doing lately and at the same time last year.
Did it work?
I tested it on a full year it had never seen, 12 November 2025 to 11 November 2026, and I made it compete against two lazy guesses: "same as this weekday last week" and "just the usual level". If a model can't beat those, it has no business being on my site.
For the whole network the model was off by 4.2% on average. The usual level was off by 6.3%, and last week by 8.9%.
Here is the part I did not expect. On ordinary days the model barely wins: 3.6% against 3.8%. An ordinary Tuesday looks like the last few Tuesdays, and no amount of machine learning changes that. Nearly all of the gain comes from holiday periods, where the lazy guess is off by 28% and the model by under 10%. Which is fine, because those are exactly the days I wanted to know about.
It also holds up with distance. One day ahead it is off by 3.7%, and 28 days ahead by 4.8%.
Ordinary days
- Model3.6%
- Usual level for that weekday3.8%
- Same weekday last week6.6%
Around public holidays and festive seasons
- Model9.8%
- Usual level for that weekday28.1%
- Same weekday last week28.7%
Things I tried that did not help
I am listing these because the failures taught me more than the wins.
School holidays. I was sure these would matter. I added the school calendar, tested on two different periods, and the result went up in one and down in the other. Out it went.
Telling the model to care more about holidays. I gave holiday days extra weight in training. It got worse on exactly the days it was meant to help.
Rain. This one hurt a little. With the day's actual rainfall the network error dropped by about 5%. But that is cheating: I won't know next Friday's real rainfall next Friday morning, only a forecast of it. Until I test it with real weather forecasts, it stays out.
Concerts and events. This is the one I personally care about most, and I could not find a reliable list of events to learn from. So today the model does not know Bukit Jalil has a concert on. I would rather say that plainly than have you trust it on a concert night.
The shaded range on the chart was also wrong at first. It was supposed to contain the real number 8 times out of 10, and when I checked, it managed about 6. I had to widen it using days the model had not seen, and now it lands at 77% to 79%.
Keeping it alive without a server
A forecast that is not updated is just an old chart. Every night around 11:30pm a scheduled job on GitHub downloads the newest data, forecasts the next 28 days and publishes the result, and the site picks it up. On the 1st of each month another job retrains the model on everything published so far, and only swaps it in if its forecasts stay close to the old model's. It costs me nothing to run.
The site also keeps every forecast it has shown and scores it once the real number comes out. If the model starts doing badly, it will be visible to you as well as to me.
You can try it on the homepage: pick the network, a line or your own station, and look up to 28 days ahead.
What is still missing
It cannot see a holiday that is announced at the last minute, a breakdown, or a sudden storm. Raya dates in future years are estimates until they are officially announced. New stations have very little history, so the LRT Shah Alam Line forecasts deserve less trust for now. And there is still no hourly view.
I built this with an AI coding assistant, and I am grateful for it. It did a large share of the coding, testing and debugging. What to build, which ideas to keep or throw out, and whether a result was honest enough to publish were my calls.
If you take the train in KL, try your station and tell me if it matches what you see on the platform. The code and the full test results are on GitHub.