ddbourgin / numpy-ml

Machine learning, in numpy
https://numpy-ml.readthedocs.io/
GNU General Public License v3.0
15.26k stars 3.7k forks source link

Feature request: save/load model to/from json #86

Open DannyVarod opened 1 year ago

DannyVarod commented 1 year ago

To easily use these models in a robust non-version-dependent way, an option to save/load model to/from json (either string or file) would be helpful.

E.g.

# save to json (can be stored anywhere, not just in file)
model_json = model.save_to_json()

# save to json file
with open(...) as f:
    model.save_to_json_file(f)   # create folder and parent folders if not exist

# load from json
model = Model.load_from_json(json)

# load from json file
with open(...) as f:
    Model.load_from_json_file(f)