Introduction to the Python API for NeurEco Regression#

Note

The GUI functionality Export NeurEco to Python , see Export Tabular Regression from the GUI to the Python API, facilitates the initial transition from the usage of NeurEco with the GUI to its usage with the Python API.

The Python API is compatible with python 3.x.
It provides all the GUI’s features and more.
Two options are available for installing the python API:
  • Via the NeurEco GUI: Click on Python drop-list in the GUI and select Install NeurEco package to python. A window containing all the python environments found on the machine will appear. Select the environment to add NeurEco wrapper to it, and click on Install package. This will automatically install the python API for the chosen distribution.

    NeurEco GUI main window
  • Via the installation scripts: run the Install.py script that comes with the Python package (this will install it in the environment used to run the installation script).

Note

  • The Python API uses numpy Python library. Make sure it is installed in the used environment.

  • The Python API uses matplotlib Python library. This library will be imported only if the user uses the plotting methods (plot_network, plot_compression_coefficients…).

  • The Python API uses TensorFlow 2.x and Keras Python libraries only when exporting to Keras (neureco2keras).

To work with the Tabular NeurEco models in Python, import NeurEcoTabular library:

from NeurEco import NeurEcoTabular as Tabular

To initialize a NeurEco object to handle the Regression problem:

model = Tabular.Regressor()

All the methods provided by the Regressor class, can be viewed by calling the __method__ attributes:

print(model.__methods__)
*** NeurEco Tabular Regressor methods: ***
- load
- save
- delete
- evaluate
- build
- get_input_count
- get_output_count
- load_model_from_checkpoint
- get_number_of_networks_from_checkpoint
- get_weights
- export_fmu
- export_c
- export_onnx
- export_vba
- compute_error
- plot_network
- forward_derivative
- gradient
- set_weights
- perform_input_sweep

To understand what each parameter of any method does and how to use it, print the doc of the method:

print(model.export_c.__doc__)
exports a NeurEco tabular model to a header file
:param h_file_path: path where the .h file will be saved
:param precision: string: optional: "float" or "double": precision of the weights in the h file
:return: export_status: int: 0 if export is ok, other if otherwise.

Note

In addition to these method, embed license allows to convert a NeurEco Tabular model to a Keras model, see Convert a NeurEco Regression model to a Keras model.