How To Predict Multiple Time Series With Scikit-Learn (With a Sales Forecasting Example)

You got a lot of time series and want to predict the next step (or steps). What should you do now? Train a model for each series? Is there a way to fit a model for all the series together? Which is better?

I have seen many data scientists think about approaching this problem by creating a single model for each product. Although this is one of the possible solutions, it’s not likely to be the best.

Here I will demonstrate how to train a single model to predict multiple time series at the same time. This technique usually creates powerful models that help teams win machine learning competitions and can be used in your project.

  1. Hi Mario Filho,

    Thanks for providing this solution, but I think there is a flaw in the working. You are training the model again for predicting future weeks.
    Whereas, you should your model’s output as input to predict future weeks. Then only the mean error will make sense.

    • Not necessarily, you can retrain your model every week when you get new data (if you get new data every week, of course). If you use the model output you can accumulate errors. If you need predictions for later weeks you need to change the approach to not use last week inputs and have the label far in the future.

  2. Navon Francis

    Hi Mario,

    I have a question regarding this article: http://mariofilho.com/how-to-predict-multiple-time-series-with-scikit-learn-with-sales-forecasting-example/

    When the model is built, you say “Now, to get predictions for each time series, your just need put the product code, week and compute the new features.”

    How are you supposed to implement this? Say I want to make a prediction of product 1 for week 52, or product 40 for week 53.

    Thank you!

    • In this example we get new sales numbers every week and try to predict the next week. So when implemented in production we have a retraining/prediction cycle every week when we get new data. If you want predictions for weeks greater than next week I recommend changing the approach (inputs and outputs).

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *