facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.29k stars 4.51k forks source link

Prophet Optimization error #2535

Open Cooliebaj opened 9 months ago

Cooliebaj commented 9 months ago

Please Help asap I have a project due in a couple days and I am trying to use prophet here is my code and error message. I am creating a stock market prediction web app. Every time I put in code for m=prophet() and try to use it this is what I get.

RuntimeError: Error during optimization! Command 'C:\Users\jorba\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\prophet\stan_model\prophet_model.bin random seed=47623 data file=C:\Users\jorba\AppData\Local\Temp\tmpdettfxal\x5flnp8b.json init=C:\Users\jorba\AppData\Local\Temp\tmpdettfxal\g2_1pp2n.json output file=C:\Users\jorba\AppData\Local\Temp\tmpdettfxal\prophet_modeli_5ct35q\prophet_model-20231201164815.csv method=optimize algorithm=newton iter=10000' failed: Traceback: File "C:\Users\jorba\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 534, in _run_script exec(code, module.dict) File "C:\Users\jorba\PROJECT.py", line 47, in m.fit(df_train) File "C:\Users\jorba\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\prophet\forecaster.py", line 1232, in fit self.params = self.stan_backend.fit(stan_init, dat, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jorba\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\prophet\models.py", line 128, in fit self.stan_fit = self.model.optimize(args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jorba\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\cmdstanpy\model.py", line 696, in optimize raise RuntimeError(msg)

PROJECT.txt

2victor2 commented 9 months ago

I'm also with the same problem... digging deeper into the logs I saw that this error is being raised in cmdstanpy backend.

RuntimeError: Error during optimization! Command '/home/victor/Projects/Infra/natto-forecaster/venv/lib/python3.9/site-packages/prophet/stan_model/prophet_model.bin random seed=99561 data file=/tmp/tmpdy1bc6ti/l6ubkhnj.json init=/tmp/tmpdy1bc6ti/5gzpegdq.json output file=/tmp/tmpdy1bc6ti/prophet_modelxvyk50xw/prophet_model-20231201112246.csv method=optimize algorithm=newton iter=10000' failed: console log output:

method = optimize
  optimize
    algorithm = newton
      newton
    jacobian = 0 (Default)
    iter = 10000
    save_iterations = 0 (Default)
id = 1 (Default)
data
  file = /tmp/tmpdy1bc6ti/l6ubkhnj.json
init = /tmp/tmpdy1bc6ti/5gzpegdq.json
random
  seed = 99561
output
  file = /tmp/tmpdy1bc6ti/prophet_modelxvyk50xw/prophet_model-20231201112246.csv
  diagnostic_file =  (Default)
  refresh = 100 (Default)
  sig_figs = -1 (Default)
  profile_file = profile.csv (Default)
num_threads = 1 (Default)

Rejecting initial value:
  Error evaluating the log probability at the initial value.
Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'prophet.stan', line 130, column 2 to column 19)

Initialization between (-2, 2) failed after 1 attempts. 
 Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
Initialization failed.

I've already tried changing the parameters, specifying initial values and clearing Nan values but, since doesn't seem to be in Prophet initialization, any of them worked. My code if needed:

        # Create a new Prophet model with the loaded parameters
        prophet_model = Prophet(**model)

        # Fit the model with the data
        df_for_prophet = data[["DTNEG", "QTDNEG"]].rename(
            columns={"DTNEG": "ds", "QTDNEG": "y"}
        )
        # Convert 'y' column to numeric, coercing errors
        df_for_prophet["y"] = pd.to_numeric(df_for_prophet["y"], errors="coerce")

        # Drop rows with NaN values after conversion
        df_for_prophet = df_for_prophet.dropna(subset=["y"])
        # Set options to display more rows and columns
        pd.set_option("display.max_rows", None)
        pd.set_option("display.max_columns", None)
        # print(
        #     {
        #         "pickle_parameters": {**model},
        #         "Loaded Prophet model for product": product,
        #         "model_name": model_name,
        #         "df": df_for_prophet,
        #     }
        # )
        prophet_model.fit(df_for_prophet) # error is being raised inside this function
        # Reset display options to default values
        pd.reset_option("display.max_rows")
        pd.reset_option("display.max_columns")

Thanks in advance

Borgna02 commented 5 months ago

Same problem, prophet 1.1.5:

16:35:26 - cmdstanpy - INFO - Chain [1] start processing 16:35:26 - cmdstanpy - INFO - Chain [1] done processing 16:35:26 - cmdstanpy - ERROR - Chain [1] error: terminated by signal 3221225657 Optimization terminated abnormally. Falling back to Newton. 16:35:27 - cmdstanpy - INFO - Chain [1] start processing 16:35:27 - cmdstanpy - INFO - Chain [1] done processing 16:35:27 - cmdstanpy - ERROR - Chain [1] error: terminated by signal 3221225657 Traceback (most recent call last): File "C:\Users\danyb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\prophet\models.py", line 121, in fit self.stan_fit = self.model.optimize(**args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\danyb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\cmdstanpy\model.py", line 659, in optimize raise RuntimeError(msg) RuntimeError: Error during optimization! Command 'C:\Users\danyb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\prophet\stan_model\prophet_model.bin random seed=82529 data file=C:\Users\danyb\AppData\Local\Temp\tmpz_z9dcxk\chl1mqe7.json init=C:\Users\danyb\AppData\Local\Temp\tmpz_z9dcxk\cfjxi_pi.json output file=C:\Users\danyb\AppData\Local\Temp\tmpz_z9dcxk\prophet_modelq8hb3fxt\prophet_model-20240421163526.csv method=optimize algorithm=lbfgs iter=10000' failed:

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "d:\Uni\3 anno\1 sem\AI\progetti_corso_AI\progetto_finale\src\fbprophet\fbprhphet_prova.py", line 73, in model.fit(future_df.reset_index().rename(columns={'index': 'ds', 'daily_return_NVDA': 'y'})) File "C:\Users\danyb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\prophet\forecaster.py", line 1232, in fit self.params = self.stan_backend.fit(stan_init, dat, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\danyb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\prophet\models.py", line 128, in fit self.stan_fit = self.model.optimize(args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\danyb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\cmdstanpy\model.py", line 659, in optimize raise RuntimeError(msg) RuntimeError: Error during optimization! Command 'C:\Users\danyb\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\prophet\stan_model\prophet_model.bin random seed=9043 data file=C:\Users\danyb\AppData\Local\Temp\tmpz_z9dcxk\s2v4x2tf.json init=C:\Users\danyb\AppData\Local\Temp\tmpz_z9dcxk\8u4b2w1y.json output file=C:\Users\danyb\AppData\Local\Temp\tmpz_z9dcxk\prophet_modelqfm1twda\prophet_model-20240421163527.csv method=optimize algorithm=newton iter=10000' failed:

Tuyen92 commented 5 months ago

hi Borgna02. I had the same problem like you about the

_self.stanfit = self.model.optimize(**args)

I want to ask you how to handle this error if you already solve it

Borgna02 commented 4 months ago

hi Borgna02. I had the same problem like you about the

_self.stanfit = self.model.optimize(**args)

I want to ask you how to handle this error if you already solve it

Hi, i solved it executing the script on ubuntu 22.04, prophet 1.1.1 and holidays 0.18.0.

I don't know if at the moment is possible to execute it on windows..

Tuyen92 commented 4 months ago

I've tried using Prophet 1.1.1 and holidays 0.18.0 on Windows 11, but I'm still encountering the same error.