facebook / facebook/prophet

model_to_json raises Object of type 'int64' is not JSON serializable on Model object

Đang mở
#1,848 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
20.4k
Fork
4.6k
Merge trung bình
19 giờ 52 phút
Pull request đã merge (30 ngày)
1

Mô tả

After training a prophet model with the following code

```python
model = Prophet(
holidays=self._specialPeriods,
growth='logistic',
changepoint_prior_scale=metric.changepoint_prior_scale,
seasonality_prior_scale=metric.seasonality_prior_scale
)

# Select the training features needed for this metric
trainingData = clientWeeklyData[['created_on', metric.name, *metric.features]]

# Set metric params on data
trainingData.rename({'created_on':'ds', metric.name:'y'}, axis=1, inplace=True) # Prepare data in correct format for the prophet.
trainingData['cap'] = metric.cap
trainingData['floor'] = metric.floor

model.add_country_holidays(country_name='UK')
for parameter in metric.features:
model.add_regressor(parameter)

self._models.setdefault(client, {})[metric.name] = model.fit(trainingData)
```

where `trainingData` and `self._specialPeriods` are pandas data frames

```
# trainingData.dtypes
ds datetime64[ns]
y float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
**** float64
cap int64
floor int64
```
You receive the following error when you come to save the model using model_to_json

```
>>>model_to_json(model)
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/vscode/.vscode-server/extensions/ms-python.python-2021.3.658691958/pythonFiles/lib/python/debugpy/__main__.py", line 45, in
cli.main()
File "/home/vscode/.vscode-server/extensions/ms-python.python-2021.3.658691958/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
run()
File "/home/vscode/.vscode-server/extensions/ms-python.python-2021.3.658691958/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 331, in run_module
run_module_as_main(target_as_str, alter_argv=True)
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/workspaces/optimised_package_margin/components/pipeline/pipeline/__main__.py", line 100, in
model.save(args.model_path)
File "/workspaces/optimised_package_margin/components/pipeline/pipeline/forecast_model.py", line 331, in save
json.dump(model_to_json(model), handle)
File "/home/vscode/.local/lib/python3.6/site-packages/fbprophet/serialize.py", line 91, in model_to_json
return json.dumps(model_json)
File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'int64' is not JSON serializable
```
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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.