Is there a way to train a model on some data and then apply the trained model on some other test data and make predictions based on that test data (without re-training the model)?
This is how it would look:
m = Prophet()
m.fit(train_df)
forecast = m.predict(some_test_data + future_for_test_data)
@synchronization, not sure If I understand you correctly what exactly you mean by other test data? But yes, once you train a model, you can apply it on any test set that you have in mind. But keep the following in mind: in the absence of external regressors, you just need to provide the horizon of your forecast (remember that that prophet's model estimates (non-linear) functions of time) so you need to essentially provide future values for "t", which is implicitly done for you do by specifying the horizon. Basically (in the absence of external regressors), your "test data" is a sequence for the future t.
Example with 5 steps ahead so "future" t = 1....5
m = Prophet()
myfit <- fit.prophet(m, train_data)
future <- make_future_dataframe(myfit_new, periods = 5)
forecast <- predict(myfit, future)
If you add external regressors the logic is the same, but you just need to provide them in the prediction part.
Let me know if this makes sense.
@APramov Thank you for your response. Let me re-phrase my question:
In other words, for future week number n, I want to take advantage of all the original data of the weeks 1 to n-1, while my model is only trained on weeks 1-85
@synchronization , thanks, I understand better what you would like to do now.
Here is what I think about your question - someone please correct me if I have missed out something completely.
I will split my answer in two parts, since you did not specify if you are thinking of including external regressors or not:
A) Using the model without external regressors:
Short answer: In this case, at week 87 there is no way to incorporate the information of week 86 without re-estimating the model (at least to my knowledge). As far as I know there is no way to update the parameters by considering the additional data sequentially.
Long answer:
Keep in mind that the Prophet's model basic structure (equation 1 from the paper) has various functions only of time, it is does not explicitly depend on past values of the quantity that you are modeling (say y).
The formula is like this:
y(t) = g(t) + s(t) + h(t) + error_t
So, on to your question. If you estimate the model (without external regressors) using 1-85, you will estimate the functional form (or rather, the parameters) of the g, s and h functions. Hence, when you do your prediction, you just put in the next "t" and you have an estimate for y(t+1, t+2) etc.
In this sense, if you are not re-estimating the model, when you are at t = 85, you can predict all the forecasts up to t = 103 (and beyond). You don't need to expand the window one week forward each time to incorporate the last week's value, because the last week's value does not feature at all in the formula that I have written above (Formula 1).
Every forecasted future value is just a (complicated) function of time (t).
B) Using the model with external regressors:
I think a way out of this would be consider, say, the previous week's value as an external regressor, i.e. expanding the equation e.g. like this:
y(t) = g(t) + s(t) + h(t) + beta.y_(t-1) + error_t
See https://github.com/facebook/prophet/issues/928 and
https://facebook.github.io/prophet/docs/seasonality,_holiday_effects,_and_regressors.html#additional-regressors for more details
In this way, you explicitly account for the past values of y and you could thus use them in the way that you described to do forecasts (see my previous post and the link to the quick start guide)
Ad-hoc, I can't see a problem doing that equation, apart from a case when beta would be 1 (i.e. you would have a unit root) and your process would be nonstationary (you can test for that).
If you have other external regressors, you can add them in the same way.
Again, this are just my (initial) thoughts, I'd be happy to see what @bletham view on this.
@APramov Thank you VERY MUCH for your detailed response. You made it very clear.
@APramov Thank you VERY MUCH for your detailed response. You made it very clear.
Very nice, if this answered your question maybe you could close the issue?