question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

stan_backend is missing when loading model from json

See original GitHub issue
from fbprophet.serialize import model_to_json, model_from_json
with open("serialized_model.json", "r") as fin:
    fb_model = model_from_json(json.load(fin))

df_cv = cross_validation(fb_model, ............)

It produces this error,

File "C:\Users\XXXXX\.conda\envs\fbprophet7\lib\site-packages\fbprophet\diagnostics.py", line 295, in prophet_copy
    stan_backend=m.stan_backend.get_type()
AttributeError: 'NoneType' object has no attribute 'get_type'

Code snippet from diagnostics.py

m2 = m.__class__(
        growth=m.growth,
        n_changepoints=m.n_changepoints,
        changepoint_range=m.changepoint_range,
        changepoints=changepoints,
        yearly_seasonality=False,
        weekly_seasonality=False,
        daily_seasonality=False,
        holidays=m.holidays,
        seasonality_mode=m.seasonality_mode,
        seasonality_prior_scale=m.seasonality_prior_scale,
        changepoint_prior_scale=m.changepoint_prior_scale,
        holidays_prior_scale=m.holidays_prior_scale,
        mcmc_samples=m.mcmc_samples,
        interval_width=m.interval_width,
        uncertainty_samples=m.uncertainty_samples,
        stan_backend=m.stan_backend.get_type()
    )

It errors out when it tries to copy another model object I can comment out “stan_backend=m.stan_backend.get_type()” to make it work, not sure if it has any complication or raise any concern.

Can be easily replicated when you load a model from json, using FBProphet v0.7 on windows.

from fbprophet.serialize import model_to_json, model_from_json
with open('serialized_model.json', 'r') as fin:
    fb_model = model_from_json(json.load(fin))
fb_model.stan_backend.get_type()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-104-5351aed8e4ed> in <module>
----> 1 fb_model.stan_backend.get_type()
 
AttributeError: 'NoneType' object has no attribute 'get_type'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
blethamcommented, Apr 2, 2021

The fix has been pushed to pypi in the new v1.0 (with the new package name, prophet)

2reactions
blethamcommented, Mar 4, 2021

This is fixed in eb6b8f6. Here is a test case:

import json
from fbprophet.serialize import model_from_json
from fbprophet.diagnostics import cross_validation


with open('serialized_model_v0.7.1.json', 'rb') as fin:
    model = model_from_json(json.load(fin))

df_cv = cross_validation(model, initial='15 days', horizon='1 day', period='2 days')  # Now works
Read more comments on GitHub >

github_iconTop Results From Across the Web

Frustrating problems with Pystan (anaconda Python)
Hello everyone, I am new to Stan, and I am currently trying to run a Bayesian model using Pystan as my interface.
Read more >
Time Series Part 3: Forecasting with Facebook Prophet: An Intro
Prophet is robust to missing data and shifts in the trend, and typically handles outliers well. ... m = model_from_json(json.load(fin)) # Load model...
Read more >
How to convert from Tensorflow.js (.json) model into ...
Convert the Keras HDF5 file into a SavedModel (standard Tensorflow model file) or directly into .tflite file using the TFLiteConverter.
Read more >
Deploying Prophet model with custom environments on IBM ...
In Python, models should not be saved with pickle; the Stan backend attached to the model object will not pickle well, and will...
Read more >
Prophet: Automatic Forecasting Procedure - Morioh
Prophet is robust to missing data and shifts in the trend, and typically ... You can also choose an experimental alternative stan backend...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found