"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "notebooks/additional_topics.ipynb" between
prophet-1.0.tar.gz and prophet-1.1.tar.gz

About: Prophet is a tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.

additional_topics.ipynb  (prophet-1.0):additional_topics.ipynb  (prophet-1.1)
skipping to change at line 125 skipping to change at line 125
"source": [ "source": [
"In Python, models should not be saved with pickle; the Stan backend attache d to the model object will not pickle well, and will produce issues under certai n versions of Python. Instead, you should use the built-in serialization functio ns to serialize the model to json:" "In Python, models should not be saved with pickle; the Stan backend attache d to the model object will not pickle well, and will produce issues under certai n versions of Python. Instead, you should use the built-in serialization functio ns to serialize the model to json:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"import json\n",
"from prophet.serialize import model_to_json, model_from_json\n", "from prophet.serialize import model_to_json, model_from_json\n",
"\n", "\n",
"with open('serialized_model.json', 'w') as fout:\n", "with open('serialized_model.json', 'w') as fout:\n",
" json.dump(model_to_json(m), fout) # Save model\n", " fout.write(model_to_json(m)) # Save model\n",
"\n", "\n",
"with open('serialized_model.json', 'r') as fin:\n", "with open('serialized_model.json', 'r') as fin:\n",
" m = model_from_json(json.load(fin)) # Load model" " m = model_from_json(fin.read()) # Load model"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The json file will be portable across systems, and deserialization is backw ards compatible with older versions of prophet." "The json file will be portable across systems, and deserialization is backw ards compatible with older versions of prophet."
] ]
}, },
{ {
skipping to change at line 191 skipping to change at line 190
"source": [ "source": [
"m = Prophet(growth='flat')" "m = Prophet(growth='flat')"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Note that if this is used on a time series that doesn't have a constant tre nd, any trend will be fit with the noise term and so there will be high predicti ve uncertainty in the forecast.\n", "Note that if this is used on a time series that doesn't have a constant tre nd, any trend will be fit with the noise term and so there will be high predicti ve uncertainty in the forecast.\n",
"\n", "\n",
"To use a trend besides these three built-in trend functions (piecewise line ar, piecewise logistic growth, and flat), you can download the source code from github, modify the trend function as desired in a local branch, and then install that local version. This PR provides a good illustration of what must be done t o implement a custom trend (https://github.com/facebook/prophet/pull/1466/files) , as does this one that implements a step function trend (https://github.com/fac ebook/prophet/pull/1794) and this one for a new trend in R (https://github.com/f acebook/prophet/pull/1778)." "To use a trend besides these three built-in trend functions (piecewise line ar, piecewise logistic growth, and flat), you can download the source code from github, modify the trend function as desired in a local branch, and then install that local version. [This PR](https://github.com/facebook/prophet/pull/1466/fil es) provides a good illustration of what must be done to implement a custom tren d, as does [this one](https://github.com/facebook/prophet/pull/1794) that implem ents a step function trend and [this one](https://github.com/facebook/prophet/pu ll/1778) for a new trend in R."
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Updating fitted models\n", "### Updating fitted models\n",
"\n", "\n",
"A common setting for forecasting is fitting models that need to be updated as additional data come in. Prophet models can only be fit once, and a new model must be re-fit when new data become available. In most settings, model fitting is fast enough that there isn't any issue with re-fitting from scratch. However, it is possible to speed things up a little by warm-starting the fit from the mo del parameters of the earlier model. This code example shows how this can be don e in Python:" "A common setting for forecasting is fitting models that need to be updated as additional data come in. Prophet models can only be fit once, and a new model must be re-fit when new data become available. In most settings, model fitting is fast enough that there isn't any issue with re-fitting from scratch. However, it is possible to speed things up a little by warm-starting the fit from the mo del parameters of the earlier model. This code example shows how this can be don e in Python:"
] ]
skipping to change at line 257 skipping to change at line 256
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"As can be seen, the parameters from the previous model are passed in to the fitting for the next with the kwarg `init`. In this case, model fitting was abo ut 5x faster when using warm starting. The speedup will generally depend on how much the optimal model parameters have changed with the addition of the new data .\n", "As can be seen, the parameters from the previous model are passed in to the fitting for the next with the kwarg `init`. In this case, model fitting was abo ut 5x faster when using warm starting. The speedup will generally depend on how much the optimal model parameters have changed with the addition of the new data .\n",
"\n", "\n",
"There are few caveats that should be kept in mind when considering warm-sta rting. First, warm-starting may work well for small updates to the data (like th e addition of one day in the example above) but can be worse than fitting from s cratch if there are large changes to the data (i.e., a lot of days have been add ed). This is because when a large amount of history is added, the location of th e changepoints will be very different between the two models, and so the paramet ers from the previous model may actually produce a bad trend initialization. Sec ond, as a detail, the number of changepoints need to be consistent from one mode l to the next or else an error will be raised because the changepoint prior para meter `delta` will be the wrong size." "There are few caveats that should be kept in mind when considering warm-sta rting. First, warm-starting may work well for small updates to the data (like th e addition of one day in the example above) but can be worse than fitting from s cratch if there are large changes to the data (i.e., a lot of days have been add ed). This is because when a large amount of history is added, the location of th e changepoints will be very different between the two models, and so the paramet ers from the previous model may actually produce a bad trend initialization. Sec ond, as a detail, the number of changepoints need to be consistent from one mode l to the next or else an error will be raised because the changepoint prior para meter `delta` will be the wrong size."
] ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### External references\n",
"These github repositories provide examples of building on top of Prophet in
ways that may be of broad interest:\n",
"* [forecastr](https://github.com/garethcull/forecastr): A web app that prov
ides a UI for Prophet.\n",
"* [NeuralProphet](https://github.com/ourownstory/neural_prophet): A Prophet
-style model implemented in pytorch, to be more adaptable and extensible."
]
} }
], ],
"metadata": { "metadata": {
"celltoolbar": "Edit Metadata", "celltoolbar": "Edit Metadata",
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
"language_info": { "language_info": {
 End of changes. 5 change blocks. 
4 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)