facebook / facebook/prophet

Second time fit could means updating fitted models

Open
#2,110 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
20.4k
Forks
4.6k
Avg merge
19h 52m
Merged PRs (30d)
1

Description

From the docs about [updating fitted model](https://facebook.github.io/prophet/docs/additional_topics.html#updating-fitted-models), we can implement:

```
def stan_init(m):
"""Retrieve parameters from a trained model.

Retrieve parameters from a trained model in the format
used to initialize a new Stan model.

Parameters
----------
m: A trained model of the Prophet class.

Returns
-------
A Dictionary containing retrieved parameters of m.

"""
res = {}
for pname in ['k', 'm', 'sigma_obs']:
res[pname] = m.params[pname][0][0]
for pname in ['delta', 'beta']:
res[pname] = m.params[pname][0]
return res
```

But, if user use custom parameters like `Prophet(weekly_seasonality=False)`, it would be nice to make that parameters persist across fitting.

So, instead of:

```python
m1 = Prophet(weekly_seasonality=False).fit(df1) # A model fit to all data except the last day

m2 = Prophet(weekly_seasonality=False).fit(df) # Adding the last day, fitting from scratch
m2 = Prophet(weekly_seasonality=False).fit(df, init=stan_init(m1)) # Adding the last day, warm-starting from m1
```

It should be something like:

```python
m = Prophet(weekly_seasonality=False)
m.fit(df1) # A model fit to all data except the last day

m.fit(df, update_model=True)
```

And inside `fit`, on *fitted moded*:

```
# only go here if already fitted
if True:
init = stan_init(m)
else:
print("Prophet object can only be fit once. Instantiate a new object.")
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.