Open Kieran-Bacon opened 3 years ago
There's probably a bug in here but I'm not exactly sure where.
Having cap
and floor
as int64s shouldn't be an issue; those values are serialized via pandas, which should be correctly handling them (at least in pd 1.2.3 that I'm testing it does). You can verify that with this code, which is how fbprophet is serializing it under the hood:
import json
json.dumps(trainingData.to_json(orient='table', index=False))
Does that work?
The holidays
input is serialized in the same way.
Other possible culprits are metric.changepoint_prior_scale
and metric.seasonality_prior_scale
; is one of these by chance an np.int64?
Otherwise I'm not sure where it's coming from. I tried to produce the error with the following code that has an int64 column in the training data and it works (using data from the examples folder on this github):
import pandas as pd
from fbprophet.serialize import model_to_json
from fbprophet import Prophet
df = pd.read_csv('../examples/example_wp_log_R.csv')
df['cap'] = 8
m = Prophet(growth='logistic')
m.add_country_holidays(country_name='UK')
m.fit(df)
print(df.dtypes)
# ds object
# y float64
# cap int64
# dtype: object
model_to_json(m) # Succeeds
Does that work for you? Otherwise could you construct a code example that I can run that produces the error?
I experienced something nearly the same. Different data type in the error (longlong), but otherwise the same problem when serializing the model. I updated fbprophet==0.7.1 to prophet==1.0.1 and I am able to write the model successfully.
I have experienced the same issue a few days back and after having multiple experiments with the data types I finally found the solution for the exception.
Basically Prophet model tries to convert a few non-core data types into core data types check the link for reference.
Unfortunately, they are not covering all the datatypes and whenever we used non-core data types for the model attributes it throws an error.
So the solution for the above problem is that use core datatypes while building prophet models like below
model = Prophet( holidays=self._specialPeriods, growth='logistic', changepoint_prior_scale=float(metric.changepoint_prior_scale), seasonality_prior_scale=float(metric.seasonality_prior_scale) )
FYI you can find out the core attribute list here
After training a prophet model with the following code
where
trainingData
andself._specialPeriods
are pandas data framesYou receive the following error when you come to save the model using model_to_json
Versions: Python 3.6.9 fbprophet 0.7.1 pandas 1.1.5
Please could you take a look into this problem - in the meantime, do I need to convert the DataFrame into something else before I pass it in to avoid having the np.int64?