model_to_json drops the fitted regressor predictor; deserialized model can't predict

Open Beginner friendly
#2,790 0 comments 0 reactions 0 assignees View on GitHub

@caiotheodoro is already working on this.

Since Nov 24, 2026.

  • #2791 by @caiotheodoro — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start in python/prophet/serialize.py: compare what model_to_json writes for each entry of extra_regressors against the keys model_from_json restores, and you will see the fitted predictor model dropped while prior_scale, standardize and mode survive. Then check python/prophet/forecaster.py for how add_regressor(..., regressor_predictor=True) stores that predictor during fit. Done means the reproduction script round-trips and m2.predict(future) equals m.predict(future); add it as a regression test under python/prophet/tests/.

Written by the indexing model from the issue text.

Description

model_to_json drops the fitted regressor predictor; deserialized model can't predict

With add_regressor(name, regressor_predictor=True), the model forecasts the
regressor itself inside predict(). model_to_json replaces the fitted
predictor with None, so after model_from_json the model can no longer
predict without a caller-supplied regressor column — it raises
ValueError: Regressor 'reg' missing from dataframe. If the caller does
supply the column, the deserialized model silently produces a different
forecast than the original (user values are used where the original generated
them from the predictor).

Reproduce

import numpy as np
import pandas as pd
from prophet import Prophet
from prophet.serialize import model_from_json, model_to_json

rng = np.random.default_rng(0)
ds = pd.date_range("2020-01-01", periods=60, freq="D")
reg = np.linspace(0, 30, 60) + rng.normal(0, 1.0, 60)
df = pd.DataFrame({"ds": ds, "y": 2.0 * reg + rng.normal(0, 0.5, 60), "reg": reg})

m = Prophet(weekly_seasonality=False, yearly_seasonality=False,
            daily_seasonality=False, uncertainty_samples=50)
m.add_regressor("reg", regressor_predictor=True)
m.fit(df)

future = pd.DataFrame({"ds": pd.date_range("2020-03-01", periods=8, freq="D")})
m.predict(future)                       # works
m2 = model_from_json(model_to_json(m))
m2.extra_regressors["reg"]["predictor"] # -> None
m2.predict(future)                      # ValueError: Regressor 'reg' missing from dataframe

Expected behavior

The serialized model round-trips the regressor predictor so m2.predict
returns the same forecast as m.predict, as documented for
model_to_json/model_from_json ("Can be deserialized with model_from_json"
and produce the same forecast).

Environment

prophet main (5cf15c0, after 1.5.0), Python 3.12, pandas 3.1.1, numpy 2.5.5,
cmdstanpy backend, macOS arm64.

Dominant language
Python
Stars
20.5k
Forks
4.6k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebook/prophet

All issues in facebook/prophet

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.