Answering your questions basing me on pm-prophet:
- In general taking the logs before fitting the regression is beneficial to fitting it, if you observe heteroskedasticity (i.e. errors funnelling out). Not too sure why it was really needed with this particular example from facebook honestly as I don’t expect this particular count data to behave crazily.
- Prophet basically models the mean of the sum of the Bx (where B are have either normal or laplacian priors) with a normal distribution. In most cases Normals provide good approximation even for count/discrete distributions in GLM and behave much better with samplers (as they are defined over continuous spaces, rather than on discrete ones).
The reason why the model is normal in the original prophet is because you have something like:
Normal(mu: seasonality TS generated from Fourier timeseries (continuous) * B1<normal/laplacian> + trend * B2<normal> + additional regressors * B3<normal/laplacian/other in pmprophet> + intercept<normal>, sigma: ..., observed = some_data)
Which usually gives good fits even with observed count data. Prophet doesn’t allow for extensions but you can indeed substitute the normal with something else in pmprophet;
m = PMProphet(df, ..., name='model')
with m.model:
pm.Normal( # replace me with whatever you like, just make sure the sampler likes me
"y_%s" % m.name,
mu=m.y, # the sum of the various regressors (trend, seasonality, intercept.. is stored in m.y)
alpha=m.priors["sigma"],
observed=(...),
)
pm.Deterministic("y_hat_%s" % m.name, m.y)
m.fit(
draws=10 ** 4,
method=Sampler.NUTS,
finalize=False # this will prevent the model from using the default normal mean fit (see https://github.com/luke14free/pm-prophet/blob/master/pmprophet/model.py#L522)
)
- I am unfortunately a bit too busy to go through your code, but you can provide custom priors to pmprophet, and therefore even hierarchical ones. This will allow you to fit multiple models at the same time (having for example an hierarchical prior on seasonality, additional regressors like CTR or whatever you want). Have a look
m.priors.
ciao!