Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell prophet to not forecast negative values

Tags:

r

forecasting

using facebooks 'Prophet' package in R for forecasting. Was wondering if there is a way use it, such that it does not forecast negative values?

Thanks!

like image 520
Elia Avatar asked Aug 19 '17 09:08

Elia


People also ask

How do prophets use forecasting?

To use Prophet for forecasting, first, a Prophet() object is defined and configured, then it is fit on the dataset by calling the fit() function and passing the data. The Prophet() object takes arguments to configure the type of model you want, such as the type of growth, the type of seasonality, and more.

Can the forecast be negative?

Calculating Forecast Error A positive value of forecast error signifies that the model has underestimated the actual value of the period. A negative value of forecast error signifies that the model has overestimated the actual value of the period.

What is cross validation in prophet?

Cross validation. Prophet includes functionality for time series cross validation to measure forecast error using historical data. This is done by selecting cutoff points in the history, and for each of them fitting the model using data only up to that cutoff point.

What is Prophet Model forecasting?

Prophet is a procedure for forecasting time series data based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality, plus holiday effects. It works best with time series that have strong seasonal effects and several seasons of historical data.


1 Answers

This is explained in the documentation in this page.

In brief, you should use "logistic" rather than "linear" growth. You must set a cap (a maximum logically possible value), and you can set a floor (if you don't set it, it will default to zero).

Assuming you have in df your data (a ds column with dates, and a y column with values).

You need to set a cap, for the past, as well as the future.

(I'm taking the 8.5 example figures included in the documentation... the value can change for each day, this should obviously be set to something meaningful for your case)

You can (but you don't need to) set a floor, for a minimum value.

df$cap <- 8.5
m <- prophet(df, growth = 'logistic')
future <- make_future_dataframe(m, periods = 1826)
future$cap <- 8.5
#future$floor <- 1.5
fcst <- predict(m, future)
plot(m, fcst)

like image 193
giocomai Avatar answered Nov 25 '22 07:11

giocomai