Prophet models
Darshika Srivastava
Associate Project Manager @ HuQuo | MBA,Amity Business School
So every time we think of implementing Time Series Modelling, The first few libraries that come to our mind are — Either Regression, ARIMA or Prophet. But do we know what is happening in the background of these algorithms and how can we further tune them to make it work for out time-series dataset
Prophet Forecasting Model — It is an Additive Regressive Model
Equation of the model is —
Prophet Forecasting Model Equation
Let’s understand these components in little depth —
In this post, I Will focus on Tuning of Trend factor. In my next post, I will share how to tune?seasonality?and other?components?of the prophet.
g(t) — Trend Factor — It implements two possibles trend models
Trend factor can be adjusted using these models
a)?Logistic growth model?—?It handles non-linear growth with saturation?( you might be wondering what does it mean now? uh .. confused ??)?Let’s understand —
Non-linear growth with saturation — The initial stage of growth is approximately exponential (geometric), as saturation begins, the growth slows to linear (arithmetic) and at maturity, growth stops.
Logistic growth with saturation (taken from solla price 1963)
Logistic Growth model
x0 — X-value of sigmoid’s point
L — Curve’s Maximum value
k — Logistic growth rate or steepness of the curve
m = Prophet(growth='logistic')
m.fit(df)
b) Piecewise Linear Model —?It is a simple modification of linear model, yet very useful. Different ranges of ??, different linear relationships occur ? A single linear model may not provide an adequate explanation or description ? Breakpoints are the value of ?? where the slope changes ? The value of breakpoints may or may not known before the analysis, when unknown it has to be estimated
By Default Prophet uses Linear model for its growth. — Constant rate of growth — It is best suitable for without saturation growth.
Piece-wise linear model
Piecewise linear model
?? be the value of the breakpoint
We can tune these parameters (trend components) in out prophet model by setting the breakpoints (also known as changepoints) and the total CAP i.e market size or capacity value — It must be specified for every row in a data frame and it doesn't have to be constant. If market size is growing then CAP can be an increasing sequence.
# Python
future = m.make_future_dataframe(periods=1826)
future['cap'] = 8.5
fcst = m.predict(future)
fig = m.plot(fcst)
Like CAP we have saturating minimal values also (known as the floor).
# Python
df['y'] = 10 - df['y']
df['cap'] = 6
df['floor'] = 1.5
future['cap'] = 6
future['floor'] = 1.5
m = Prophet(growth='logistic')
m.fit(df)
fcst = m.predict(future)
fig = m.plot(fcst)
The Library can itself choose the optimal points of trend changes by fitting the historical data.
If you want to tune them manually — you can refer?here?—
m = Prophet(changepoint_prior_scale=0.08)
Python code — By default, this parameter (changepoint_prior_scale)is set to 0.05. Increasing it will make the trend?more?flexible.
m = Prophet(changepoint_prior_scale=0.5)
forecast = m.fit(df).predict(future)
fig = m.plot(forecast)
you can manually specify the locations of potential changepoints with the?changepoints?argument
# Python
m = Prophet(changepoints=['2014-01-01'])
forecast = m.fit(df).predict(future)
fig = m.plot(forecast)
you can also set — changepoint_range parameter. By default, Prophet specifies 25 potential changepoints which are uniformly placed in the first 80% of the time series
# Python
from fbprophet.plot import add_changepoints_to_plot
fig = m.plot(forecast)
a = add_changepoints_to_plot(fig.gca(), m, forecast)
Changepoints in Red
You can change this parameter by —
m = Prophet(changepoint_range=0.9)
(based on the breakpoints you have in your data)
So If you see your trend is going upward but your actual dataset points are going downward — then you can tune these parameters to make your trend more flexible ( but do keep in mind not to overfit your data(I will share how to?cross-validate your data?in my upcoming post)).
For example — You can plot the components of the prophet equation using —
m.plot_components(forecast).
So you can tune your above parameters by looking at the trend line (blue solid line — whether is is aligning with you final output or not). If your actual point’s trend is decreasing whereas your forecasted trends seems to be increasing then you definitely need to improvize on your trend component using above discussed parameters.
For seasonality and other components please look at?part2.
Link to my GitHub repository —?https://github.com/DeeptiAgl?tab=repositories
Please do share your feedback and any questions if you have. I will try to answer them to the best of my knowledge.—