.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/jsonpickle/main.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_jsonpickle_main.py: 01. Basic example ================== Description .. GENERATED FROM PYTHON SOURCE LINES 7-62 .. code-block:: default :lineno-start: 7 # Libraries import json import numpy as np # Jsonpickle import jsonpickle import jsonpickle.ext.numpy as jsonpickle_numpy # Configure jsonpickle jsonpickle.set_preferred_backend('json') jsonpickle_numpy.register_handlers() # ------------------- # Main # ------------------- """ In order to test whether the jsonpickle encode method saves the estimators so they can be retrieved no matter the numpy version. Note that previously using pickle old estimators could not be loaded because of numpy issues. At the moment I have tested using the system (no virtual environment) using the following... $ py -m pip install numpy==1.18 $ py main.py $ py -m pip install numpy==1.19.1 $ py main.py And it works normally. .. todo: Test it through a venvpy28-jsonpickle. """ # Path path = './estimator_00.json' # Read with open(path) as json_file: d = json.load(json_file) # Show information #print(d['iteration_00']) # Show information print("\nUsing numpy... <%s>" % np.version.version) # Load estimator = jsonpickle.decode(d['iteration_00']) # Show print("\nEstimator loaded. \n %s" % estimator) print("\nPredictions completed. \n %s" % \ estimator.predict_proba(np.arange(6).reshape(1,-1))) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download__examples_jsonpickle_main.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: main.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: main.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_