# Which algorithm to use for predicting late deliveries at warehouse?

I am trying to predict risk labels of late deliveries for the upcoming 1-2 months based on 3 years of historic delivery data. The target variable is a categorical output based on how many days late a delivery was (on time, 1-2 days late, one week late, more than one week late). Input variables include things like material information, suppliers location & distance to warehouse, # of times delivery was marked as delayed and suppliers monthly quality ratings as well as information on known quality issues registered with supplier over time etc.

So looking at the information above and that I have records per year of around 500.000 delivieries from 300 suppliers I believe random forests would be a good choice to start.

However, I´m thinking it would not capture important time sensitive trends, such as a supplier all of the sudden delivering late while he was reliable the last 3 years. So what is a good way to capture time sensitive trends in RF or should I choose a different algorithm form the time-series domain? Or is there a way to combine multiple approaches?

Thanks for you input!

Yes you could add a time component if you have dates in your data. Use the functions found in this link, for your work.

Essentially you would want to see if there are day based effects such as Are deliveries late on Fridays / Friday evenings / Early mornings / Late nights / are etc.

What you'd have to do for that is to strip out the day of the week from the relevant date variables and add it as a ordinal predictor to your data. If you want to strip out individual weekday effects, use an if else function to classify the day of the week as Monday / Not Monday, Tuesday / Not Tuesday, etc. You could do something similar to month of the year, week of the year, season, etc.

You would probably want to place more weight on more recent training observations, as the performance in the upcoming 1-2 months is likely to be more influenced by performance over the past (say) 6 months than performance 2-3 years ago.

If you have a "date" feature, you could create a weight based on this. Then - if your random forest algorithm allows it - use the weight feature to influence the bootstrap sampling (observations with higher weights are more likely to be sampled). In R, the ranger random forest algorithm has a parameter called case.weights which does exactly this.

Another way of capturing a time-sensitive trend would be to create features based on "rolling" time periods - e.g. fraction of deliveries which are late within past month / 3 months / 6 months, etc. I would suggest doing this overall with reference to the date of analysis (perhaps group by delivery company), and for the individual training instances with reference to the instance's original delivery date.

Hope that helps.