mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-09-15 22:10:22 +00:00
Only encode to JSON once when serializing a Python model (#2178)
This commit is contained in:
parent
cc8c69a3ba
commit
84132a29eb
2 changed files with 4 additions and 6 deletions
|
|
@ -36,14 +36,13 @@ In Python, models should not be saved with pickle; the Stan backend attached to
|
|||
|
||||
```python
|
||||
# Python
|
||||
import json
|
||||
from prophet.serialize import model_to_json, model_from_json
|
||||
|
||||
with open('serialized_model.json', 'w') as fout:
|
||||
json.dump(model_to_json(m), fout) # Save model
|
||||
fout.write(model_to_json(m)) # Save model
|
||||
|
||||
with open('serialized_model.json', 'r') as fin:
|
||||
m = model_from_json(json.load(fin)) # Load model
|
||||
m = model_from_json(fin.read()) # Load model
|
||||
```
|
||||
The json file will be portable across systems, and deserialization is backwards compatible with older versions of prophet.
|
||||
|
||||
|
|
|
|||
|
|
@ -122,14 +122,13 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"from prophet.serialize import model_to_json, model_from_json\n",
|
||||
"\n",
|
||||
"with open('serialized_model.json', 'w') as fout:\n",
|
||||
" json.dump(model_to_json(m), fout) # Save model\n",
|
||||
" fout.write(model_to_json(m)) # Save model\n",
|
||||
"\n",
|
||||
"with open('serialized_model.json', 'r') as fin:\n",
|
||||
" m = model_from_json(json.load(fin)) # Load model"
|
||||
" m = model_from_json(fin.read()) # Load model"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue