Store a Function for Embedded Execution
You can store a user-defined Python function for embedded execution.
The following Python code creates a function that receives prediction data.
The function loads the trained model from the OML4Py datastore and returns the result by
calling the predict
method with the prediction data.
You need to register the function for embedded execution with OML by using the
oml.script.create
method. Note that this function is enclosed
within triple quotes.
func = """def error_model_predict_(X):
import oml
objs = oml.ds.load('spatial_error_ds', objs=['spatial_error'], to_globals=False)
error_model = objs['spatial_error']
pred = error_model.predict(X)
return pred.tolist()"""
oml.script.create("errorModelPredict", func, is_global=True, overwrite=True)
The oml.script.create
function adds a user-defined Python function to
the OML script repository. The is_global
parameter specifies whether to
create a global Python function or if it is available only to the current user. The
overwrite
parameter specifies whether to overwrite the Python
function if it already exists.