I want to predict sales in food-vending machines (to ultimately prevent food waste). I work with scikit learn.

My current models are not too bad, but they show seasonal patterns for underprediction (and reciprocally for overprediction). The graph shows the monthly ratio of (underprediction==True)/(observations) for one model (linear regression):

enter image description here

The graph looks similar for the other models I have tested (Ridge(), Lasso(), AdaBoostRegressor(), GradientBoostingRegressor(), ExtraTreesRegressor(), RandomForestRegressor(), ElasticNet(), KNeighborsRegressor(), DecisionTreeRegressor()). Everywhere I see patterns such as the ratio of underpredictions in May and June are higher than April and July. Or the ratio is always higher in December than in January.

What can I do so that the model picks up this pattern?

To ultimately reduce under- and overprediction and increase the model fit.

Maybe add a feature/trend - but how?

Some stylized facts:

  • Target: food items sold (per day)
  • Features: company, month, day in month, location within company (categorical), canteen (binary), no. of employees, company type, school holiday (binary), bank holiday (binary), day of week
  • Observations: 34,000 (42 vending machines)
  • Time range: 2010-2015

Planned steps after modelling underprediction:

  • Fit above mentioned models with default parameters in cross validation and pick model with lowest avg. MSE and lowest standard error (cross_validation.KFold(n=rows, n_folds=5, shuffle=True))
  • Run Grid Search on the chosen model for hyperparameter tuning
  • $\begingroup$ when analyzing daily data one needs to model/tailor the lead , contemporaneous and lag structure for each holiday individually . You are not considering day-of-the-month or level shifts or local time trends. If you post one of your time series showing beginning date I will be of more help. Make sure all days are accounted for. Also mention the country. You might want to scan stats.stackexchange.com/… to get some more pointers on how to model daily data. $\endgroup$
    – IrishStat
    Commented May 28, 2019 at 7:17

2 Answers 2


You might want to look at possible interactions that are happening in month 5, since this is the only month with more than 50% underprediction. (It seems to me they should all be around 50%, and unless there are alot more observations in month 5 there is probably something wrong with the model, or you are not taking into accout NA observations)

  • $\begingroup$ Yes, they should be around 50%. That's why the model can be improved. The ratios in the graph already take the different no. of observations across months into account. What do you mean specifically with "interactions"? Generate new features that are interactions of the current features? But which? $\endgroup$
    – tobip
    Commented Dec 15, 2015 at 17:02
  • $\begingroup$ the best way would be to look at the observations in month 5 and see if there is something different about them, perhaps create a function to generate some descriptive statistics and pass different months into it $\endgroup$
    – Allen Wang
    Commented Dec 15, 2015 at 21:26

Have you tried creating dummy variables for the months (11 not 12)? Think it will be able to handle the seasonal pattern.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.