Portfolio

Engineering notes

Our traffic model was looking at the answer

A data leak in a group assignment on SCATS traffic data: how a feature that was secretly the target got in, how I found it when rebuilding the project, and what the honest numbers look like.

By Vincent Teo · Updated

The assignment

For a group assignment, my teammates and I predicted traffic volume at road junctions in Victoria, Australia, using SCATS sensor data, which counts vehicles passing each site. We did the research the slow way, reading papers and trying things, and ended up with three approaches: XGBoost, Random Forest and a reinforcement learning agent.

It went well. The models scored well, the report came together, and we were happy with it.

Reopening it months later

Later I wanted to put the project on my portfolio, properly, with a chart a visitor could play with. That meant rebuilding it from the raw data instead of copying old screenshots. While I was at it I asked an AI model for recommendations on the modelling side.

One of the first things to come back was not a recommendation. It was a question about one of our own features: where exactly does lag_24_hours come from?

The name says "traffic at this site 24 hours ago", which is a perfectly fair thing to give a model. But the way we had built that column, it was not yesterday's value. It was the value we were asking the model to predict, under a different name. The Random Forest had the same problem with another column, a sum that was really the target.

So the models were not forecasting anything. They were copying the answer from the next seat.

The second leak was quieter

We had also split the data into training and test sets at random. For most problems that is normal. For time series it is a trap.

A random split puts 9am on a Tuesday in the test set while 8am and 10am on that same Tuesday sit in the training set. The model does not need to understand traffic to fill that gap. It only needs to draw a line between two points it has already seen. Real forecasting never gets that luxury, because tomorrow has no neighbours yet.

The reinforcement learning agent had its own version of this: the information it was shown about the current state included things from the future.

Why nobody noticed

Nothing crashes when you leak data. No warning, no red text. The only symptom is a score that looks great, and a great score is exactly what you are hoping to see, so you say thank you and move on.

That is the part that bothers me most. We were careful about plenty of things. We just never asked the unfriendly question: is this too good?

The honest version

I rebuilt it with three rules. Split by date, so the model trains on earlier weeks and is tested on later ones. Only use inputs you would really have at the moment of forecasting. And always compare against a guess that needs no model at all.

That last rule was humbling. My first clean model lost. A baseline that simply says "this site, this hour, on a typical day of this type" beat it by about 3%. Hours of work, beaten by an average.

What fixed it was changing the question. Instead of predicting the traffic volume itself, the model now predicts how far a given hour will be from the typical day. The final version is off by 7.7% of traffic volume on weeks it has never seen. That is about 17% better than "same hour last week" and about 4% better than the typical-day baseline. Weekends are still a weak spot.

Four percent is not a headline. But it is real, and I can explain where it comes from, which I could not say about the old score.

What I check now

For every feature: could I actually have this number at the moment I make the prediction? If the answer needs a pause, look at how the column is built, not at what it is called.

For time series: split by date. Always.

Before trusting a model: build the lazy baseline first. If the model cannot beat it, the model is the problem.

And if the score is amazing, get suspicious before you get happy.

This project is also why my Rapid KL forecast is built the way it is. You can see the corrected traffic model on the homepage.

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