GithubHelp home page GithubHelp logo

facebook / prophet Goto Github PK

View Code? Open in Web Editor NEW
17.7K 437.0 4.5K 65.11 MB

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.

Home Page: https://facebook.github.io/prophet

License: MIT License

Python 59.88% Stan 1.82% R 38.21% Dockerfile 0.04% Makefile 0.03% C++ 0.01%
forecasting r python

prophet's Introduction

Prophet: Automatic Forecasting Procedure

Build

PyPI Version PyPI Downloads Monthly PyPI Downloads All

CRAN Version CRAN Downloads Monthly CRAN Downloads All

Conda_Version


2023 Update: We discuss our plans for the future of Prophet in this blog post: facebook/prophet in 2023 and beyond


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. Prophet is robust to missing data and shifts in the trend, and typically handles outliers well.

Prophet is open source software released by Facebook's Core Data Science team. It is available for download on CRAN and PyPI.

Important links

Installation in R - CRAN

โš ๏ธ The CRAN version of prophet is fairly outdated. To get the latest bug fixes and updated country holiday data, we suggest installing the latest release.

Prophet is a CRAN package so you can use install.packages.

install.packages('prophet')

After installation, you can get started!

Installation in R - Latest release

install.packages('remotes')
remotes::install_github('facebook/prophet@*release', subdir = 'R')

Experimental backend - cmdstanr

You can also choose an experimental alternative stan backend called cmdstanr. Once you've installed prophet, follow these instructions to use cmdstanr instead of rstan as the backend:

# R
# We recommend running this in a fresh R session or restarting your current session
install.packages(c("cmdstanr", "posterior"), repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

# If you haven't installed cmdstan before, run:
cmdstanr::install_cmdstan()
# Otherwise, you can point cmdstanr to your cmdstan path:
cmdstanr::set_cmdstan_path(path = <your existing cmdstan>)

# Set the R_STAN_BACKEND environment variable
Sys.setenv(R_STAN_BACKEND = "CMDSTANR")

Windows

On Windows, R requires a compiler so you'll need to follow the instructions provided by rstan. The key step is installing Rtools before attempting to install the package.

If you have custom Stan compiler settings, install from source rather than the CRAN binary.

Installation in Python - PyPI release

Prophet is on PyPI, so you can use pip to install it.

python -m pip install prophet
  • From v0.6 onwards, Python 2 is no longer supported.
  • As of v1.0, the package name on PyPI is "prophet"; prior to v1.0 it was "fbprophet".
  • As of v1.1, the minimum supported Python version is 3.7.

After installation, you can get started!

Anaconda

Prophet can also be installed through conda-forge.

conda install -c conda-forge prophet

Installation in Python - Development version

To get the latest code changes as they are merged, you can clone this repo and build from source manually. This is not guaranteed to be stable.

git clone https://github.com/facebook/prophet.git
cd prophet/python
python -m pip install -e .

By default, Prophet will use a fixed version of cmdstan (downloading and installing it if necessary) to compile the model executables. If this is undesired and you would like to use your own existing cmdstan installation, you can set the environment variable PROPHET_REPACKAGE_CMDSTAN to False:

export PROPHET_REPACKAGE_CMDSTAN=False; python -m pip install -e .

Linux

Make sure compilers (gcc, g++, build-essential) and Python development tools (python-dev, python3-dev) are installed. In Red Hat systems, install the packages gcc64 and gcc64-c++. If you are using a VM, be aware that you will need at least 4GB of memory to install prophet, and at least 2GB of memory to use prophet.

Windows

Using cmdstanpy with Windows requires a Unix-compatible C compiler such as mingw-gcc. If cmdstanpy is installed first, one can be installed via the cmdstanpy.install_cxx_toolchain command.

Changelog

Version 1.1.5 (2023.10.10)

Python

  • Upgraded cmdstan version to 2.33.1, enabling Apple M2 support.
  • Added pre-built wheels for macOS arm64 architecture (M1, M2 chips)
  • Added argument scaling to the Prophet() instantiation. Allows minmax scaling on y instead of absmax scaling (dividing by the maximum value). scaling='absmax' by default, preserving the behaviour of previous versions.
  • Added argument holidays_mode to the Prophet() instantiation. Allows holidays regressors to have a different mode than seasonality regressors. holidays_mode takes the same value as seasonality_mode if not specified, preserving the behaviour of previous versions.
  • Added two methods to the Prophet object: preprocess() and calculate_initial_params(). These do not need to be called and will not change the model fitting process. Their purpose is to provide clarity on the pre-processing steps taken (y scaling, creating fourier series, regressor scaling, setting changepoints, etc.) before the data is passed to the stan model.
  • Added argument extra_output_columns to cross_validation(). The user can specify additional columns from predict() to include in the final output alongside ds and yhat, for example extra_output_columns=['trend'].
  • prophet's custom hdays module was deprecated last version and is now removed.

R

  • Updated holidays data based on holidays version 0.34.

Version 1.1.4 (2023.05.30)

Python

  • We now rely solely on holidays package for country holidays.
  • Upgraded cmdstan version to 2.31.0, enabling Apple M1 support.
  • Fixed bug with Windows installation caused by long paths.

R

  • Updated holidays data based on holidays version 0.25.

Version 1.1.2 (2023.01.20)

Python

  • Sped up .predict() by up to 10x by removing intermediate DataFrame creations.
  • Sped up fourier series generation, leading to at least 1.5x speed improvement for train() and predict() pipelines.
  • Fixed bug in how warm start values were being read.
  • Wheels are now version-agnostic.

R

  • Fixed a bug in construct_holiday_dataframe()
  • Updated holidays data based on holidays version 0.18.

Version 1.1.1 (2022.09.08)

  • (Python) Improved runtime (3-7x) of uncertainty predictions via vectorization.
  • Bugfixes relating to Python package versions and R holiday objects.

Version 1.1 (2022.06.25)

  • Replaced pystan2 dependency with cmdstan + cmdstanpy.
  • Pre-packaged model binaries for Python package, uploaded binary distributions to PyPI.
  • Improvements in the stan model code, cross-validation metric calculations, holidays.

Version 1.0 (2021.03.28)

  • Python package name changed from fbprophet to prophet
  • Fixed R Windows build issues to get latest version back on CRAN
  • Improvements in serialization, holidays, and R timezone handling
  • Plotting improvements

Version 0.7 (2020.09.05)

  • Built-in json serialization
  • Added "flat" growth option
  • Bugfixes related to holidays and pandas
  • Plotting improvements
  • Improvements in cross validation, such as parallelization and directly specifying cutoffs

Version 0.6 (2020.03.03)

  • Fix bugs related to upstream changes in holidays and pandas packages.
  • Compile model during first use, not during install (to comply with CRAN policy)
  • cmdstanpy backend now available in Python
  • Python 2 no longer supported

Version 0.5 (2019.05.14)

  • Conditional seasonalities
  • Improved cross validation estimates
  • Plotly plot in Python
  • Bugfixes

Version 0.4 (2018.12.18)

  • Added holidays functionality
  • Bugfixes

Version 0.3 (2018.06.01)

  • Multiplicative seasonality
  • Cross validation error metrics and visualizations
  • Parameter to set range of potential changepoints
  • Unified Stan model for both trend types
  • Improved future trend uncertainty for sub-daily data
  • Bugfixes

Version 0.2.1 (2017.11.08)

  • Bugfixes

Version 0.2 (2017.09.02)

  • Forecasting with sub-daily data
  • Daily seasonality, and custom seasonalities
  • Extra regressors
  • Access to posterior predictive samples
  • Cross-validation function
  • Saturating minimums
  • Bugfixes

Version 0.1.1 (2017.04.17)

  • Bugfixes
  • New options for detecting yearly and weekly seasonality (now the default)

Version 0.1 (2017.02.23)

  • Initial release

License

Prophet is licensed under the MIT license.

prophet's People

Contributors

baogorek avatar ben-schwen avatar bletham avatar davharris avatar dependabot[bot] avatar dmitryvinn avatar hoxo-m avatar igevorse avatar joseangel-sc avatar lemonlaug avatar loulo1 avatar mitchelloharawild avatar olof-hojvall avatar raajtilaksarma avatar raffg avatar raybellwaves avatar rmax avatar ryankarlos avatar salmontimo avatar sarikayamerts avatar seanjtaylor avatar seriousran avatar sss-ng avatar sukwkim avatar tcuongd avatar teramonagi avatar wardbrian avatar wsuchy avatar yoziru avatar ziye666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prophet's Issues

[feature request] weekly.seasonality.prior.scale and yearly.seasonality.prior.scale

Is there a way to break out the weights for the seasonality components so that you can vary the weight of weekly seasonality separately from yearly seasonality?

I find that often I'm very confident about the weekly seasonality and not super confident about yearly so I'd like to lower the effect of yearly seasonality and keep weekly seasonality at the same weight.

Adding these arguments would be a solution.

weekly.seasonality.prior.scale

yearly.seasonality.prior.scale

Error in R

It looks like this:
"Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! Warning message:
running command 'make -f "C:/PROGRA1/R/R-331.2/etc/i386/Makeconf" -f "C:/PROGRA1/R/R-331.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file2f455284a4.dll" OBJECTS="file2f455284a4.o"' had status 127 "

TypeError: ufunc 'isfinite' not supported for the input types

I'm getting this error after calling plot or plot_components methods.

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

My first assumption was that something was wrong with the dtypes, but they seam fine:

ds datetime64[ns]
y int64
dtype: object

I'm not sure if this has to do with numpy, matplotlib o prophet. Any ideas?

Cannot use 'pip install fbprophet' to install prophet on mac

Failed building wheel for fbprophet
Running setup.py clean for fbprophet
Failed to build fbprophet
Installing collected packages: fbprophet
Running setup.py install for fbprophet ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/private/tmp/pip-build-1Wz6u0/fbprophet/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-fHkhKl-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/fbprophet
creating build/lib/fbprophet/stan_models
INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_35bf14a7f93814266f16b4cf48b40a5a NOW.
error: command 'cc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/private/tmp/pip-build-1Wz6u0/fbprophet/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-fHkhKl-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-1Wz6u0/fbprophet/

Adding daily seasonality

When I pass data with multiple observations per day via a date-time stamp, it appears to truncate the time and produce daily estimates only. Is it possible to add daily seasonality (e.g. hour granularity)? We have strong daily, weekly and yearly signals in our operations data which we would like to flag as anomalous.

Thanks for the great tool.

install failed in centos(CentOS release 6.8 (Final)) with python3.5

I have installed pystan by pip install pystan and already installed gcc by yum install gcc, but when I install prophet by pip install fbprophet, I got this reply:

# bin/pip install fbprophet
Collecting fbprophet
  Using cached fbprophet-0.1.post1.tar.gz
Requirement already satisfied: pandas in ./lib/python3.5/site-packages (from fbprophet)
Requirement already satisfied: pystan in ./lib/python3.5/site-packages (from fbprophet)
Requirement already satisfied: pytz>=2011k in ./lib/python3.5/site-packages (from pandas->fbprophet)
Requirement already satisfied: numpy>=1.7.0 in ./lib/python3.5/site-packages/numpy-1.12.0-py3.5-linux-x86_64.egg (from pandas->fbprophet)
Requirement already satisfied: python-dateutil>=2 in ./lib/python3.5/site-packages (from pandas->fbprophet)
Requirement already satisfied: Cython!=0.25.1,>=0.22 in ./lib/python3.5/site-packages (from pystan->fbprophet)
Requirement already satisfied: six>=1.5 in ./lib/python3.5/site-packages (from python-dateutil>=2->pandas->fbprophet)
Building wheels for collected packages: fbprophet
  Running setup.py bdist_wheel for fbprophet ... error
  Complete output from command /user/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-26bikl4m/fbprophet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpko_q49elpip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/fbprophet
  creating build/lib/fbprophet/stan_models
  INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_35bf14a7f93814266f16b4cf48b40a5a NOW.
  error: command 'gcc' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for fbprophet
  Running setup.py clean for fbprophet
Failed to build fbprophet
Installing collected packages: fbprophet
  Running setup.py install for fbprophet ... error
    Complete output from command /user/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-26bikl4m/fbprophet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-xjarhmkf-record/install-record.txt --single-version-externally-managed --compile --install-headers /user/include/site/python3.5/fbprophet:
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/fbprophet
    creating build/lib/fbprophet/stan_models
    INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_35bf14a7f93814266f16b4cf48b40a5a NOW.
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/user/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-26bikl4m/fbprophet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-xjarhmkf-record/install-record.txt --single-version-externally-managed --compile --install-headers /user/include/site/python3.5/fbprophet" failed with error code 1 in /tmp/pip-build-26bikl4m/fbprophet/

Could you help me to fix this problem? Thanks in advance.

AttributeError: 'numpy.timedelta64' object has no attribute 'days'

My dateframe has the following dtypes:

ds datetime64[ns]
y float64
dtype: object

When I try to run m.fit(df), the traceback points to an AttributeError here.

It does work, though, if I try the following instead:

  t = np.array(
            (dates - pd.datetime(1970, 1, 1))
            .dt.days
            .astype(np.float)
        )

I referred to this post on StackOverflow.

Would this be preferable or would it break something else?

Use dygraphs for plotting

dygraphs makes some great interactive plots. You can zoom in, hover, etc. I coded it to be the generic plot method but replacing ggplot2 is a bit extreme. So maybe the generic plot should call either the ggplot2 or dygraphs functions depending on an argument flag, like plot(m, forecast, dygraphs=TRUE)?

In terms of compatibility it can be used from the console and in rmarkdown documents for rendering to HTML or pdf docs (pdf requires the latest versions of knitr and webshot).

#' Plot the prophet forecast.
#'
#' @param x Prophet object.
#' @param fcst Data frame returned by predict(m, df).
#' @param uncertainty Boolean indicating if the uncertainty interval for yhat
#'  should be plotted. Must be present in fcst as yhat_lower and yhat_upper.
#' @param actual.color Color of points for actual data
#' @param forecast.color Color of forecast line
#' @param forecast.label Text for legend
#' @param actual.label Text for legend
#' @param forecast.pattern Type of line for forecast. Must be one of c("dashed", "dotted", "dotdash", "solid").
#' @param actual.size Size of points for actual data
#' @param forecast.size Thickness of line for forecast data
#' @param legend.width Width of legend
#' @param group Group to associate this plot with. The x-axis zoom level of plots within a group is automatically synchronized.
#' @param ... additional arguments
#' @importFrom magrittr "%>%"
#' @return A dygraph plot.
#'
#' @examples
#' \dontrun{
#' history <- data.frame(ds = seq(as.Date('2015-01-01'), as.Date('2016-01-01'), by = 'd'),
#'                       y = sin(1:366/200) + rnorm(366)/10)
#' m <- prophet(history)
#' future <- make_future_dataframe(m, periods = 365)
#' forecast <- predict(m, future)
#' plot(m, forecast)
#' }
#'
#' @export
plot.prophet <- function(x, fcst, uncertainty=TRUE, 
                         actual.color='black', forecast.color='#0072B2',
                         forecast.label='Predicted', actual.label='Actual',
                         forecast.pattern=c("dashed", "dotted", "dotdash", "solid"),
                         actual.size=2, forecast.size=1,
                         legend.width=400,
                         ...) 
{
    forecast.pattern <- match.arg(forecast.pattern)
    
    # create data.frame for plotting
    df <- df_for_plotting(x, fcst)

    # build variables to include, or not, the uncertainty data
    if(uncertainty && exists("yhat_lower", where = df))
    {
        colsToKeep <- c('y', 'yhat', 'yhat_lower', 'yhat_upper')
        forecastCols <- c('yhat_lower', 'yhat', 'yhat_upper')
    } else
    {
        colsToKeep <- c('y', 'yhat')
        forecastCols <- c('yhat')
    }
    
    # convert to xts for easier date handling by dygraph
    # haven't dealt with cap yet
    dfTS <- xts(dplyr::select_(df, .dots=colsToKeep), order.by=df$ds)
    
    # base plot
    dyBase <- dygraphs::dygraph(dfTS, group=group)
    
    dyBase %>% 
        # plot forecast and ribbon
        dygraphs::dySeries(forecastCols, label=forecast.label, 
                           color=forecast.color, strokePattern=forecast.pattern, 
                           strokeWidth=forecast.size) %>% 
        # plot actual values
        dygraphs::dySeries('y', label=actual.label, drawPoints=TRUE, 
                           pointSize=actual.size, strokeWidth=0, 
                           color=actual.color) %>% 
        # allow zooming
        dygraphs::dyRangeSelector() %>% 
        # make unzoom button
        dygraphs::dyUnzoom() %>% 
        # control legend width
        dygraphs::dyLegend(width=legend.width)
}

R: Weekday Plot fails on non-English locales

In prophet_plot_components, the following snippet for the weekly seasonality plot fails on non-english locales:

df.s <- df %>% dplyr::mutate(dow = factor(weekdays(ds), levels = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")))

This produces NA for all weekdays due to the hardcoding of factor names.

As a result no useful weekday plot is created.

image

Will prophet work for discontinuous seasonal data?

we have two months(dec and jan) data for 4 years (2013-2016) we trying to predict for (dec 2017- jan 2018). It is non-continuous data which is seasonal for which we are trying to forecast using prophet.
will prophet account for this discontinuity if not please let us know how to implement.

Thanks in advance :-)

Possible licensing issue re: BSD vs GPL

Hi, looks like a great package, planning on using it. However, just wanted to give you a heads-up about possible licensing issues that a colleague bought up:

"The package is based on Stan and Rstan (+PyStan). Prophet claims it is under a 3-clause BSD licence. While Stan itself also uses a BSD licence, RStan and Pystan use GPLv3 licences. GPL licences require all derived work to be also GPL licensed. It may be possible to claim it's a linking scenario but I'm not sure whether that's the case or if the claim holds at all."

holiday label error

If you label a holiday with an underscore it causes an error in parsing. "promo_100" and "promo_150" will be sliced to "promo" and only one will be evaluated.

Causes plotting error when you plot components

prophet_plot_components(m, forecast) Error in rowSums(df[, holiday.comps]) : 'x' must be an array of at least two dimensions

Hi,

Everything seems to work fine when I forecast my data without holidays, and mostly works fine when I add in holidays, except for prophet_plot_components(m, forecast) which gives me the error

Error in rowSums(df[, holiday.comps]) : 'x' must be an array of at least two dimensions

I can plot/view the forecast, but just not the plot components. When I try to view df[, holiday.comps] I get the error

Error in [.data.frame(df, , holiday.comps) : undefined columns selected

Any thoughts would be much appreciated!

Thanks

file dump request

Could you please provide the filedump used in example? wikipediatrend package is not usable at the moment since
stats.grok.se is down and it's unknown if it will be available again.

as an alternative, this site can be used: https://tools.wmflabs.org/
pageviews.zip

inst folder is missing in R pkg

Thank you for your open source!

It seems R package in this Github does not contain inst folder,
although there is "stan" folder in R library when I install it from CRAN
i.e. dir.exists(system.file("stan", package = 'prophet')) == T

so therefore it will show build break with R CMD INSTALL command on the cloned repo since there is no such folder.

periodically data load using partial_fit

In order to fit the model with data from other sources, like Prometheus, would be nice to have partial_fit implemented, so new data can be added periodically.

install pystan on windows 7 Anaconda prompt with python 3.5.3 successfully but failed to pass the test

Already installed python 3.53, pystan,Visual C++ 2015 Build Tools-win7
when I test the pystan :

import pystan
model_code = 'parameters {real y;} model {y ~ normal(0,1);}'
model = pystan.StanModel(model_code=model_code)
y = model.sampling(n_jobs=1).extract()['y']
y.mean() # with luck the result will be near 0

the output:
INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_5944b02c79788fa0db5b3a93728ca2bf NOW.

-0.016311821652416087

This may means that stan work well on this test.
But when I test pystan in this way :

import pystan
sm = pystan.StanModel(model_code=open('prophet_linear_growth.stan').read())

output:
INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_35bf14a7f93814266f16b4cf48b40a5a NOW.

DistutilsExecError Traceback (most recent call last)
F:\Anaconda2\envs\py33\lib\distutils_msvccompiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends)
381 try:
--> 382 self.spawn(args)
383 except DistutilsExecError as msg:

F:\Anaconda2\envs\py33\lib\distutils_msvccompiler.py in spawn(self, cmd)
500 os.environ['path'] = self._paths
--> 501 return super().spawn(cmd)
502 finally:

F:\Anaconda2\envs\py33\lib\distutils\ccompiler.py in spawn(self, cmd)
908 def spawn(self, cmd):
--> 909 spawn(cmd, dry_run=self.dry_run)
910

F:\Anaconda2\envs\py33\lib\distutils\spawn.py in spawn(cmd, search_path, verbose, dry_run)
37 elif os.name == 'nt':
---> 38 _spawn_nt(cmd, search_path, dry_run=dry_run)
39 else:

F:\Anaconda2\envs\py33\lib\distutils\spawn.py in _spawn_nt(cmd, search_path, verbose, dry_run)
80 raise DistutilsExecError(
---> 81 "command %r failed with exit status %d" % (cmd, rc))
82

DistutilsExecError: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2

During handling of the above exception, another exception occurred:

CompileError Traceback (most recent call last)
in ()
1 import pystan
----> 2 sm = pystan.StanModel(model_code=open('prophet_linear_growth.stan').read())

F:\Anaconda2\envs\py33\lib\site-packages\pystan\model.py in init(self, file, charset, model_name, model_code, stanc_ret, boost_lib, eigen_lib, verbose, obfuscate_model_name, extra_compile_args)
307
308 try:
--> 309 build_extension.run()
310 finally:
311 if redirect_stderr:

F:\Anaconda2\envs\py33\lib\distutils\command\build_ext.py in run(self)
337
338 # Now actually compile and link everything.
--> 339 self.build_extensions()
340
341 def check_extensions_list(self, extensions):

F:\Anaconda2\envs\py33\lib\distutils\command\build_ext.py in build_extensions(self)
446 self._build_extensions_parallel()
447 else:
--> 448 self._build_extensions_serial()
449
450 def _build_extensions_parallel(self):

F:\Anaconda2\envs\py33\lib\distutils\command\build_ext.py in _build_extensions_serial(self)
471 for ext in self.extensions:
472 with self._filter_build_errors(ext):
--> 473 self.build_extension(ext)
474
475 @contextlib.contextmanager

F:\Anaconda2\envs\py33\lib\distutils\command\build_ext.py in build_extension(self, ext)
531 debug=self.debug,
532 extra_postargs=extra_args,
--> 533 depends=ext.depends)
534
535 # XXX outdated variable, kept here in case third-part code

F:\Anaconda2\envs\py33\lib\distutils_msvccompiler.py in compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends)
382 self.spawn(args)
383 except DistutilsExecError as msg:
--> 384 raise CompileError(msg)
385
386 return objects

CompileError: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2

I don't know the reason . could you help me fix this problem? thks a lot!

Time-varying seasonality in prophet

I was wondering: is there a way of taking into account a time-varying seasonality?

For instance, an increase in level is often accompanied by an increase in the magnitude of the seasonal oscillations.

The following example in R:

library(prophet)
library(forecast)
data(gas)
df <- data.frame(ds = as.Date.ts(gas), y = as.numeric(gas))
m <- prophet(df)
future <- make_future_dataframe(m, periods = 365)
forecast <- predict(m, future)
plot(m, forecast)

In this case, it looks like prophet overestimates the oscillations at the beginning and underestimates them at the end.

How should I deal with such a feature?

multivariate modeling

I see from issue #18 that there are no concrete plans yet for prophet to handle multivariate data. I am interested in tackling this feature; any pointers on where to start?

My application area is vehicle traffic. For example, numbers of cars and trucks in each lane moving past a point (yes I also read that sub-daily data is also not yet well supported). While I can predict traffic lane by lane by car by truck, it would make more sense to model all lanes and vehicle types at once, since they are related (lots of trucks in the right lanes means fewer cars in those lanes, more cars in left lanes, etc etc.).

Duplicate holiday dates produces an error

With a large list of holidays I've found that there will be accidents with the manual creation process. It is helpful if the error message tells you what is wrong instead of giving you an error that doesn't mean anything.

If you run this:

library(prophet)
data = read.csv("https://raw.githubusercontent.com/facebookincubator/prophet/master/R/tests/testthat/data.csv")

holidays <- data_frame(
  holiday = 'duplicate',
  ds = as.Date(c("2012-05-18", "2012-05-18")),
  lower_window = 0,
  upper_window = 0
)

prophet(data, holidays = holidays)

This is the error:

Error in seq.default(.$lower_window, .$upper_window) : 
  'from' must be of length 1

A fix would be to check for duplicate dates and throw an error that says there are redundant holiday dates.

Cannot use 'pip install fbprophet' to install prophet on windows 10 with python 3.6.0

Already installed python 3.60, pystan and Visual C++ 2015 Build Tools-win10

error message as follow after I use pip install fbprophet:

Command "d:\ProgramData\Anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\lwx\\AppData\\Local\\Temp\\pip-build-phg6epsq\\fbprophet\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\lwx\AppData\Local\Temp\pip-6ts715hu-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\lwx\AppData\Local\Temp\pip-build-phg6epsq\fbprophet\

And I tried to install from source code which I download from https://pypi.python.org/pypi/fbprophet/0.1.post1
Use python setup.py install and error message as follows:

c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2784: 'Eigen::Matrix<boost::math::tools::promote_args<RT1,RT2,float,float,float,float>::type,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> stan::math::add(const T1 &,const Eigen::Matrix<T2,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &)': could not deduce template argument for 'const Eigen::Matrix<T2,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &' from 'Eigen::Matrix<stan::math::var,-1,-1,0,-1,-1>' d:\ProgramData\Anaconda3\lib\site-packages\pystan\stan\lib\stan_math_2.14.0\stan/math/prim/mat/fun/add.hpp(72): note: see declaration of 'stan::math::add' c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2784: 'Eigen::Matrix<boost::math::tools::promote_args<RT1,RT2,float,float,float,float>::type,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> stan::math::add(const Eigen::Matrix<T1,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &,const T2 &)': could not deduce template argument for 'const Eigen::Matrix<T1,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &' from 'stan::math::var' d:\ProgramData\Anaconda3\lib\site-packages\pystan\stan\lib\stan_math_2.14.0\stan/math/prim/mat/fun/add.hpp(50): note: see declaration of 'stan::math::add' c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2784: 'Eigen::Matrix<boost::math::tools::promote_args<RT1,RT2,float,float,float,float>::type,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> stan::math::add(const Eigen::Matrix<T1,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &,const Eigen::Matrix<T2,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &)': could not deduce template argument for 'const Eigen::Matrix<T1,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &' from 'stan::math::var' d:\ProgramData\Anaconda3\lib\site-packages\pystan\stan\lib\stan_math_2.14.0\stan/math/prim/mat/fun/add.hpp(27): note: see declaration of 'stan::math::add' c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2672: 'elt_multiply': no matching overloaded function found c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2672: 'stan::math::add': no matching overloaded function found c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2780: 'Eigen::Matrix<boost::math::tools::promote_args<RT1,RT2,float,float,float,float>::type,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> stan::math::add(const T1 &,const Eigen::Matrix<T2,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &)': expects 2 arguments - 1 provided d:\ProgramData\Anaconda3\lib\site-packages\pystan\stan\lib\stan_math_2.14.0\stan/math/prim/mat/fun/add.hpp(72): note: see declaration of 'stan::math::add' c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2780: 'Eigen::Matrix<boost::math::tools::promote_args<RT1,RT2,float,float,float,float>::type,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> stan::math::add(const Eigen::Matrix<T1,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &,const T2 &)': expects 2 arguments - 1 provided d:\ProgramData\Anaconda3\lib\site-packages\pystan\stan\lib\stan_math_2.14.0\stan/math/prim/mat/fun/add.hpp(50): note: see declaration of 'stan::math::add' c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2780: 'Eigen::Matrix<boost::math::tools::promote_args<RT1,RT2,float,float,float,float>::type,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> stan::math::add(const Eigen::Matrix<T1,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &,const Eigen::Matrix<T2,R,C,|_Rows==&&_Cols!=?:_Cols==&&_Rows!=?:,_Rows,_Cols> &)': expects 2 arguments - 1 provided d:\ProgramData\Anaconda3\lib\site-packages\pystan\stan\lib\stan_math_2.14.0\stan/math/prim/mat/fun/add.hpp(27): note: see declaration of 'stan::math::add' c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2672: 'normal_log': no matching overloaded function found c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2974: 'stan::math::normal_log': invalid template argument for 'T_y', type expected d:\ProgramData\Anaconda3\lib\site-packages\pystan\stan\lib\stan_math_2.14.0\stan/math/prim/scal/prob/normal_log.hpp(120): note: see declaration of 'stan::math::normal_log' c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2780: 'return_type<T_y,T_loc,T_scale,double,double,double>::type stan::math::normal_log(const T_y &,const T_loc &,const T_scale &)': expects 3 arguments - 2 provided d:\ProgramData\Anaconda3\lib\site-packages\pystan\stan\lib\stan_math_2.14.0\stan/math/prim/scal/prob/normal_log.hpp(44): note: see declaration of 'stan::math::normal_log' c:\users\lwx\appdata\local\temp\tmp4z5vcu1o\anon_model_35bf14a7f93814266f16b4cf48b40a5a.hpp(368): error C2672: 'stan::math::accumulator<T__>::add': no matching overloaded function found with [ T__=stan::math::var ] error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

Prophet plot 2 figures instead of 1

Hey, I do not know what's wrong with my code, but every time I invoke Prophet plotting function it's always plot 2 figures instead of just 1.

Example:
prophet_plot

I'm running python2.7, on Ubuntu 14.04 laptop.
Thanks!

'Enum' object has no attribute 'OPTIM'

m.fit(df)

ERROR:main:'Enum' object has no attribute 'OPTIM'

pandas: 0.19.2
numpy: 1.12.0
fbprophet: 0.1.post1
pystan: 2.14.0.0
OSX Python 2.7

Thanks!

exported functions

Hi there,

Since the get_changepoint... functions are documented in the help files should those be exported or are they just used internally?

Many thanks,
Michael

fit error

I have installed the prophet for python in Linux, but when i use the command
m = Prophet()
m.fit(df);
there is a error as follow:
AttributeError: StanModel instance has no attribute 'fit_class'

can you tell me the cause?Please

Group by and use an aggregation

fit fails if there is more than one record with the same timestamp.
Could you add an optional user-supplied aggregation function that could be applied on a group by instead?

Unable to fit model: absolute parameter change was below tolerance

When attempting to run Prophet().fit(df), I receive the following error:

           ds     y
0  2014-04-01    47
1  2014-05-01    94
2  2014-06-01    93
3  2014-07-01   277
4  2014-08-01   195
5  2014-09-01   190
6  2014-10-01   649
7  2014-11-01   584
8  2014-12-01  1440
9  2015-01-01   607
10 2015-02-01  1272
11 2015-03-01   637
12 2015-04-01   414
13 2015-05-01  1151
14 2015-06-01   555
15 2015-07-01   134
16 2015-08-01   455
17 2015-09-01   617
18 2015-10-01   744
19 2015-11-01  1310
20 2015-12-01  2849
21 2016-01-01   657
22 2016-02-01  1684
23 2016-03-01  1096
24 2016-04-01   155
25 2016-05-01   223
26 2016-06-01   152
27 2016-07-01   205
28 2016-08-01   255
29 2016-09-01   301
30 2016-10-01   141
31 2016-11-01    71
32 2016-12-01   680
33 2017-01-01   378
34 2017-02-01   118
STAN OPTIMIZATION COMMAND (LBFGS)
init = user
save_iterations = 1
init_alpha = 0.001
tol_obj = 1e-12
tol_grad = 1e-08
tol_param = 1e-08
tol_rel_obj = 10000
tol_rel_grad = 1e+07
history_size = 5
seed = 1749226207
initial log joint probability = -3.26242
    Iter      log prob        ||dx||      ||grad||       alpha      alpha0  # evals  Notes
      99       53.3753    0.00233329       77.8508      0.6097      0.6097      146
     156       54.4942   0.000250196        95.193   2.407e-06       0.001      264  LS failed, Hessian reset
     199       54.5156   2.51015e-07       85.6303      0.3645      0.3645      321
     219       54.5157   9.72858e-09       72.2706      0.3959      0.3959      346
Optimization terminated normally:
  Convergence detected: absolute parameter change was below tolerance

From what I can tell, this is an error from the R package gmo. However, I'm not familiar enough with the underlying statistics to understand what exactly about my data is causing the issue.

How would I make prophet use another day than Sunday for weekly frequency ?

Hey, I'm trying Prophet, and time series forecast in general, and I'm already getting pretty impressive results.

My initial data is 1 value every week, but on Fridays only, and Prophet makes predictions for Sundays only. Is there a way I can change this behavior ?

Thank you, and sorry if the question is stupid :)

Prophet forecasting questions

Hello Sean,

I have the following questions:

  1. Would you be able to share or upload on the git notebooks folder the code you used for Figure 4 and 5 of your paper?
    https://facebookincubator.github.io/prophet/static/prophet_paper_20170113.pdf it will be a good reference and will give the users more familiarization on the usage of Prophet vs the other models

  2. Sometimes forecasting is such a pain because let's say the forecast package only knows TS object format and then when XTS or ZOO is used all the underlying attributes are lost once the forecast function is called. In my example here https://github.com/karlarao/forecast_examples/blob/master/storage_forecast (see storage.R) I had to stick with using seq to generate the POSIXct time intervals and store it in a dataframe.
    I see in Prophet that you don't use any TS/XTS as well and I think you are handling your time series with the function prophet::make_future_dataframe. Did you have the same issues with TS/XTS objects? and do you still have to do a lot of massaging/pre-processing when you generate your time series data to feed to Prophet?

  3. Can Prophet handle more fine grained data like minutes or seconds?

  4. On performance evaluation I read the https://github.com/facebookincubator/prophet/blob/master/notebooks/uncertainty_intervals.ipynb showing uncertainty intervals. And of course the Figure 4 and 5 of your paper. Do you still do the other methods of evaluation/validation like the steps highlighted below?

forecast step by step: 
    eyeball the data
        raw data    
        data exploration
        periodicity
        ndiff (how much we should difference)
        decomposition - determine the series components (trend, seasonality etc.)
            x = decompose(AirPassengers, "additive")
            mymodel = x$trend + x$seasonal; plot(mymodel)           # just the trend and seasonal data
            mymodel2 = AirPassengers - x$seasonal ; plot(mymodel2)  # orig data minus the seasonal data
        seasonplot 
    process data
        create xts object
        create a ts object from xts (coredata, index, frequency/periodicity)
        partition data train,validation sets        
    graph it 
        tsoutliers (outlier detection) , anomaly detection (AnomalyDetection package)
        log scale data
        add trend line (moving average (centered - ma and trailing - rollmean) and simple exponential smoothing (ets))
   >performance evaluation
   >     Type of seasonality assessed graphically (decompose - additive,etc.)
   >     detrend and seasonal adjustment (smoothing/deseasonalizing)
   >     lag-1 diff graph
   >     forecast residual graph
   >     forecast error graph
   >     acf/pacf (Acf, tsdisplay)
   >         raw data
   >         forecast residual
   >         lag-1 diff
   >     autocorrelation 
   >         fUnitRoots::adfTest() - time series data is non-stationary (p value above 0.05)
   >         tsdisplay(diff(data_ts, lag=1)) - ACF displays there's no autocorrelation going on (no significant lags out of the 95% confidence interval, the blue line) 
   >     accuracy
   >     cross validation https://github.com/karlarao/forecast_examples/tree/master/cross_validation/cvts_tscvexample_investigation
   >     forecast of training
   >     forecast of training + validation + future (steps ahead)       
    forecast result
        display prediction intervals (forecast quantile)
        display the actual and forecasted series
        displaying the forecast errors
        distribution of forecast errors
  1. I'm also curious how do you parallelize Prophet when you have to deal with many time series and bigger data sets? because I think under the hood it does monte carlo which is pretty compute intensive (please correct me if I'm wrong)

Thank you again for sharing Prophet!

-Karl

Weekday component graph labels shifted by 1 day

We should be seeing peaks on Friday and Sunday, but instead see them on Monday and Saturday
screen shot 2017-02-27 at 3 36 26 pm
I'd be willing to admit that I was wrong about where our peaks lie, except for the weird lack of label on the last tick, and the fact that the documentation shows this graph starting on Sunday.

sub day trending

daily trending is nice but why not having at hour trending option? predicting bandwith or connection number at the hour seems more useful (in those exmaples) to daily estimates.

nice job btw

Missing tick in weekly forecast components plot (Python API)

In the Python API, the first tick seems to be missing in the weekly forecast components plot. You can see this comparing the two images in the documentation:

  • Python API

  • R API

The result is, that all other ticks move by one position, leaving the last one empty.

Can we use it to forecast different peoples' daily page views for the Wikipedia simultaneously?

In the examples, I see we can use it to forecast the time series of daily page views for the Wikipedia page for Peyton Manning. If I get many quarterbacks' data and want to forecast their page views in one model, is it possible? Because I think there should be many same features in their time series, such as periodic seasonality, holidays and other potential features. The model should be better if it can see many other people's data. Is it right? Thanking you!

Extension to hourly components?

First, prophet is super cool! I'm already playing around with some health related data. I have intraday data, but it looks like prophet doesn't really care, and only wants daily data. Has there been discussion of allowing for intraday data?

Two rows with same date object throws issue


TypeError Traceback (most recent call last)
in ()
1 m = Prophet()
----> 2 m.fit(df);

/Users/korymathewson/anaconda2/lib/python2.7/site-packages/fbprophet/forecaster.pyc in fit(self, df)
340
341 self.set_changepoints()
--> 342 A = self.get_changepoint_matrix()
343 changepoint_indexes = self.get_changepoint_indexes()
344

/Users/korymathewson/anaconda2/lib/python2.7/site-packages/fbprophet/forecaster.pyc in get_changepoint_matrix(self)
191
192 def get_changepoint_matrix(self):
--> 193 changepoint_indexes = self.get_changepoint_indexes()
194
195 A = np.zeros((self.history.shape[0], len(changepoint_indexes)))

/Users/korymathewson/anaconda2/lib/python2.7/site-packages/fbprophet/forecaster.pyc in get_changepoint_indexes(self)
184 # the historical data.
185 indexes.append(row_index.get_loc(cp))
--> 186 return np.array(indexes).astype(np.int)
187
188 def get_changepoint_times(self):

TypeError: long() argument must be a string or a number, not 'slice'

forecaster.py refers to deleted pickle files

forecaster.py refers to "linear_growth.pkl" file in get_linear_model() method. This file is deleted from the repo, so on replicating the examples given in this repo: ( as stated in example notebooks)

m = Prophet()
m.fit(df)

Throws file not found error.

Quick Background:

  1. Installed PyStan successfully.
  2. Ran a couple of PyStan examples to make sure correct installation.
  3. Since, pip install fbprophet fails on windows 10 with Visual Studio 14.0, I installed fbprophet by navigating to "prophet/python" and running "pip install -e . "

Thanks in advance for looking into this issue.

-AT

Clarification on how prophet deals with weekly data (holidays)

Hi,

My data is weekly (Mondays), and I've been using a holidays dataframe like so:

BlackFridays <- data_frame(
  holiday = 'BlackFriday',
  ds = as.Date(c('2007-11-26', '2008-12-01', '2009-11-30', '2010-11-29', '2011-11-28', '2012-12-10', 
                  '2013-12-02', '2014-11-28', '2015-11-27', '2016-11-25', '2017-11-24')),
  lower_window = 3,
  upper_window = 3
)

When I set the lower/upper windows, for my weekly data would this be the number of weeks either side, or would it be the number of days still? Does it make any difference if the holiday dates are Mondays (same as my weekly data) or on other days? Just trying to get to grips with how Prophet actually sees and deals with weekly data.

Thanks

prophet_plot_components() error in rowSums(df[, holiday.comps]) : 'x' must be numeric

I'm having an error while trying to plot components (prophet_plot_components(m, fcst)) after forecasting with holidays. The error was:

Error in rowSums(df[, holiday.comps]) : 'x' must be numeric

To illustrate the error, I run some piece of the function. So, this is what my holiday.comps in prophet_plot_components like:

> holiday.comps <- unique(m$holidays$holiday)
> holiday.comps
[1] New Year's Eve Weekends      
Levels: New Year's Eve Weekends

It has two levels: NYE and Weekends.

So, this is what my df[, holiday.comps].

> head(df[, holiday.comps])
          ds        y
1 2017-01-01      1.0
2 2017-01-02 615000.0
3 2017-01-03 672000.0
4 2017-01-04 567000.0
5 2017-01-05 456000.0
6 2017-01-06 512300.0
7 2017-01-06      1.0

Do this looks wrong? My holidays are only the days where y=1

And the error is in:

 Error in rowSums(df[, holiday.comps]) : 'x' must be numeric

ValueError: Changepoints must fall within training data

I try to fit the dataframe, but got ValueError, how to avoid this?

shop_2
Out[91]:
ds y
358 2016-06-18 71.0
359 2016-06-19 45.0
360 2016-06-20 62.0
361 2016-06-21 52.0
362 2016-06-22 76.0
363 2016-06-23 68.0
364 2016-06-24 63.0
365 2016-06-25 106.0
366 2016-06-26 64.0
367 2016-06-27 68.0
368 2016-06-28 58.0
369 2016-06-29 53.0
370 2016-06-30 46.0
371 2016-07-01 55.0
372 2016-07-02 55.0
373 2016-07-03 75.0
374 2016-07-04 54.0
375 2016-07-05 55.0
376 2016-07-06 57.0
377 2016-07-07 54.0
378 2016-07-08 94.0
379 2016-07-09 83.0
380 2016-07-10 77.0
381 2016-07-11 59.0
382 2016-07-12 59.0
383 2016-07-13 57.0
384 2016-07-14 57.0
385 2016-07-15 57.0
386 2016-07-16 62.0
387 2016-07-17 60.0
.. ... ...
464 2016-10-02 110.0
465 2016-10-03 102.0
466 2016-10-04 90.0
467 2016-10-05 121.0
468 2016-10-06 93.0
469 2016-10-07 90.0
470 2016-10-08 70.0
471 2016-10-09 77.0
472 2016-10-10 68.0
473 2016-10-11 68.0
474 2016-10-12 63.0
475 2016-10-13 56.0
476 2016-10-14 71.0
477 2016-10-15 119.0
478 2016-10-16 97.0
479 2016-10-17 75.0
480 2016-10-18 59.0
481 2016-10-19 71.0
482 2016-10-20 88.0
483 2016-10-21 103.0
484 2016-10-22 127.0
485 2016-10-23 125.0
486 2016-10-24 47.0
487 2016-10-25 80.0
488 2016-10-26 61.0
489 2016-10-27 68.0
490 2016-10-28 103.0
491 2016-10-29 102.0
492 2016-10-30 104.0
493 2016-10-31 67.0

[136 rows x 2 columns]

In [92]: m.fit(shop_2)

ValueError Traceback (most recent call last)
in ()
----> 1 m.fit(shop_2)

/usr/local/lib/python3.5/dist-packages/fbprophet/forecaster.py in fit(self, df)
339 seasonal_features = self.make_all_seasonality_features(history)
340
--> 341 self.set_changepoints()
342 A = self.get_changepoint_matrix()
343 changepoint_indexes = self.get_changepoint_indexes()

/usr/local/lib/python3.5/dist-packages/fbprophet/forecaster.py in set_changepoints(self)
159 too_high = max(self.changepoints) > self.history['ds'].max()
160 if too_low or too_high:
--> 161 raise ValueError('Changepoints must fall within training data.')
162 elif self.n_changepoints > 0:
163 # Place potential changepoints evenly throuh first 80% of history

ValueError: Changepoints must fall within training data.

python fit throws error

When performing Prophet.fit(df), i get following error

AttributeError: 'numpy.timedelta64' object has no attribute 'days'

error can be attributed to below given operation present in fbprophet/forecaster.py in method fourier_series()

t = np.array((dates - pd.datetime(1970, 1, 1)) .apply(lambda x: x.days) .astype(np.float))

as per my understanding we are trying to get the number of days since 1st Jan 1970 to current date. In this case it's apply(lambda x: x.days) which is causing this problem as numpy.timedelta64 class has no days attribute. Changing above operation to below and using pandas inbuilt function solves the problem

t = np.array((dates - pd.datetime(1970, 1, 1)) .dt.days .astype(np.float))

I wanted to report a bug fix but did not know how to do it.

Platform information
Linux - 2.6.32-431.23.3.el6.x86_64 (ab obtained by uname -r)
python=2.7.1
anaconda=2.7.1
since, fbprophet has been installed in a conda environment, all its dependencies has been statisfied

Which other dependencies for Python+Linux?

Am following the instructions in the official docs, and had all the mentioned deps in place to install fbprophet in my virtualenv (see screen below):

The Error

But apparently, there seem to be some other (OS-specific?) dependencies one might need to have in place, so as to finally successfully install the package. It's rather annoying, because the package deps-check indicated all other deps are satisfied, but during the build, possibly around pystan phase, the build fails, and the error seems to indicate there's some other package - possibly a library package, that's required for the build to work.

So, for those who have gotten this to work on a vanilla Debian, which other packages did you have to install?

Note: I've already tried to install python-dev, build-essentials, libxml2-dev and libxslt1-dev. But none of these seem to solve this. I hate having to just follow blind-install workarounds as some popular SO answers for such scenarios recommend. So, what do we do?

plot individual components of holidays

Having holidays as an aggregate view in prophet_plot_components is concise but there should maybe be an option to view holiday components individually.

Here is some code that if put in the prophet_plot_components function would separate out the holiday components.

df.s <- cbind(ds = df$ds, df[, holiday.comps])
df.s_tidy <- tidyr::gather_(df.s,key_col = "holiday", value = "effect", gather_cols = holiday.comps)
gg.holidays <- ggplot2::ggplot(df.s_tidy, ggplot2::aes(x = ds, 
                                                   y = effect)) + 
                          ggplot2::geom_line(color = forecast.color, na.rm = TRUE) + 
                          ggplot2::facet_wrap(~ holiday, ncol = 1)

predict is recompiling stan model each time

The pre-compiled model from CRAN doesn't work on my machine. Forcing a recompilation every time prophet() is called. I'm on windows x64.

I stepped through the loading code, and it was all working, but stanm@mk_cppmodule(stanm) always threw an error. This could be because I have my stan compiler default set to -O3 (and the module was compiled with -02). Not sure.

Most importantly, uninstalling the package, then re-installing from source fixed it all up. Maybe windows binary packages don't work great? Probably worth a line of documentation. Much faster now :).

Minimum pystan version

The setup.py file declares the minimum version as pystan>=2.8. However, with that version I get the following error:

ValueError: Failed to parse Stan model 'anon_model_35bf14a7f93814266f16b4cf48b40a5a'. Error message:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:

Illegal statement beginning with non-void expression parsed as
  gamma[i]
Not a legal assignment, sampling, or function statement.  Note that
  * Assignment statements only allow variables (with optional indexes) on the left;
    if you see an outer function logical_lt (<) with negated (-) second argument,
    it indicates an assignment statement A <- B with illegal left
    side A parsed as expression (A < (-B)).
  * Sampling statements allow arbitrary value-denoting expressions on the left.
  * Functions used as statements must be declared to have void returns


ERROR at line 33

 32:      for (i in 1:S) {
 33:        gamma[i] = -t[s_indx[i]] * delta[i];
            ^
 34:      }

PARSER EXPECTED: "}"

Digging further the operator = has been introduced in v2.10.0 release. See https://github.com/stan-dev/stan/blob/develop/RELEASE-NOTES.txt#L141

I think prophet should either state pystan>=2.10.0 as requirement or fix the assignment operator to be <-. I'd say the former option is better looking forward as <- is actually deprecated in latest pystan releases.

predict error

Hi

Some times the predict function will work fine at the start of a new session but then it will give errors other times. an example is give here.

screen shot 2017-03-02 at 1 15 19 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.