1

I am trying to predict ambulance demand for the next hour, for a city area in the USA, based on previous demand, weather, large people gatherings, and similar spatio-temporal factors - using Machine Learning.

I modelled the problem by binning time into 1-hour bins, as those short time horizon predictions should provide most value. I would provide these predictions to potential users in hourly intervals. I tried both timeseries and regression approaches, but as I am only predicting one value in the future, regression is much easier to implement, and reacts better to sudden changes in features, while timeseries models produce smooth prediction curves which don't help me.

But by binning demand into hourly bins, the target variable is very spiky, and has sudden jumps between values 0, 1, 3, 0, etc - and is very hard to predict. Apart from being hard to predict, the binning has an effect that would be bad in real-world applications. Let's say I have the following emergencies: 12:45 - 1 ambulance 14:01 - 3 ambulances 14:45 - 1 ambulance

For hourly bins [12:00, 13:00), [13:00, 14:00), [14:00, 15:00), the demand would be: 1, 0, 4. BUT, 3 of the 4 ambulances in [14:00, 15:00) were very near 13:00. So if I have some features at 13:00 that would reflect this increase in demand, the model would get confused, as the demand is happening in the next bin.

My first question is: is my approach correct, and is there a simple way to fix the problem I'm having? (demand close to bin limits)

After talking to some colleagues at University, they have recommended that I try smoothing out the demand curve using moving averages. Thus, I could 'distribute' some of the demand of 3 at 14:01 to its neighbouring bin, [12:00, 13:00).

The approach would be:

  1. Resample raw data about emergencies into 1-minute bins
  2. Apply a moving average (rolling mean) of W window size, let's say W=60
  3. Shift the results by -30 ( =-W/2 ), so the demand is distributed to the left and right to the minute when it was happening.

I'm not very experienced, so I have a simple question: Does it make sense to smoothen out the target demand curve? If not MA, could exponential MA help? I found one post, Use of smoothed target variable when evaluating forecasting performance, that says that predicting smoothened demand doesn't translate to predicting regular demand. But if my project ever hits the shelves, potential customers would have use of my model - because, if I do predict higher values than 0 for [13:00, 14:00), based on smoothened demand, I would still get some value from the predictions, as the predicted demand would happen just a minute later - at 14:01.

My last question is about the shift. When creating my training dataset, it makes sense to distribute the demand in a minute to the left and right, in order to mitigate the binning effects. If the W=60 is too large, I can also lower it to W=5 - thus, only the demand that happens in interval 14:00-14:04 would be distributed to the [13:00, 14:00) bin.

But when I'm creating samples for inference, it seems that I would lose some data. If I'm predicting for [14:00, 15:00), and there was demand of 3 in 13:55, then the demand would be distributed to the left bin, and to the right bin. But, because I don't keep track of the target variable in inference samples (it's what I'm trying to predict), the part that was supposed to be distributed to the right would be lost. Or, I could potentially keep track of it as another feature. Does the shift make sense?

Sorry for the long post, but I lack rigorous training and would really need some help in validating these ideas. Even though some of them may not be methodologically correct, I ask of you to also look at the practical applications of my model. I already managed to follow the demand trend and produce smooth prediction curves. Now I'm more interested in predicting sudden increases and producing alerts of high demand.

  • Related? It sure seems like part of your issue is an inability to predict the apparent anomalies, which is precisely the subject of the link. – Dave Dec 05 '23 at 18:01

1 Answers1

2

I will be brutal: I think you are on the wrong track.

Your description of the problems with binning timestamped data is correct in principle. However:

  • The timestamps themselves are imprecise, so the exact same situation could have resulted in slightly different timestamps if the caller hadn't dropped their mobile phones in the excitement. Optimizing a model to capture random fluctuations in data collection is not a good idea.
  • Yes, binning makes a difference here. But you won't be looking at just five calls for ambulances. You will be looking at multiple years of data. (At least I hope so, because you won't be able to capture the New Year's Eve effect otherwise.) One-off effects like this are effectively noise once you look at all your data. And see below on what to do with noise.

You appear unhappy that time series forecasting methods "only" give you smooth predictions. In the absence of any predictors that give you advance signals about spikes, that is precisely what they should be doing. Please take a look at the threads here. If all you know is the day of week, the hour of day, and the day of year, it makes no sense to predict a spike, because based on all this information, there is only a small difference between this hour and the same hour one week earlier or later, or the next hour, or the same hour tomorrow or yesterday - and all these differences should be captured in your model via seasonality. If you have information about an active shooter, by all means include that in your model, and that will likely give you a spike. (And you likely won't need a model for this kind of disaster response.)

I would argue that if you are forecasting for ambulance service provision, you should not pay overly much attention to the mean forecast. Rather, aim for sufficiently high quantile forecasts. You will not be able to predict when there is a pileup on the local interstate (beyond including the weather, but even with the worst of weather, often enough nothing beyond fender benders happens, simply because people adjust their driving to the weather). But you can capture the probability of high ambulance demand, and plan accordingly. Quantile forecasts are especially important in highly granular time series, because these are usually intermittent, and a mean forecast of a demand for 0.3 ambulances per hour is much less useful than a quantile forecast that tells you that the demand will not exceed 3 with 90% confidence.

Anyway, I do hope you account for the involved. Here are a few ideas, and we did use ambulance demand as an example, though on much less granular levels. With your highly granular data, it may well be that the signal is so weak that modeling it makes your forecasts worse (Kolassa, 2016, Foresight). On how to improve forecasts, you may want to look at How to know that your machine learning problem is hopeless?

Finally, if you really do want to address the binning issue, I would recommend that you run 12 different models, where each one shifts the hourly bins by five more minutes (60/5=12), then reconcile the forecasts in a temporal aggregation framework (Boylan & Babai, 2016 or Kourentzes et al., 2014). However, I reiterate that I believe this to be the wrong direction.

Stephan Kolassa
  • 123,354