11.5.7.4 Load a User-Defined Python Function
Use the oml.script.load
function to load a user-defined Python function from the script repository into a Python session.
The syntax of the function is the following:
oml.script.load(name, owner=None)
The name
argument is a string that specifies the name of the user-defined Python function to load from the OML4Py script repository.
The optional owner
argument is a string that specifies the owner of the user-defined Python function or None
(the default). If owner=None
, then this function finds and loads the user-defined Python function that matches name
in the following order:
-
A user-defined Python function that the current user created.
-
A global user-defined Python function that was created by another user.
The oml.script.load
function returns an oml.script.script.Callable
object that references the named user-defined Python function.
Example 11-13 Using the oml.script.load Function
This example loads user-defined Python functions from the script repository and pulls them to the local Python session. For the creation of the user-defined Python functions, see Example 11-11.
import oml
# Load the MYLM and GLBLM user-defined Python functions.
MYLM = oml.script.load(name="MYLM")
GMYLM = oml.script.load(name="GLBLM")
# Pull the models to the local Python session.
MYLM(oml_iris.pull()).coef_
GMYLM(oml_iris.pull())
Listing for This Example
>>> import oml
>>>
>>> # Load the MYLM and GLBLM user-defined Python functions.
>>> MYLM = oml.script.load(name="MYLM")
>>> GMYLM = oml.script.load(name="GLBLM")
>>>
>>> # Pull the models to the local Python session.
... MYLM(oml_iris.pull()).coef_
array([[ 0.49588894, 0.82924391, -0.31515517, -0.72356196, -1.02349781]])
>>> GMYLM(oml_iris.pull())
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1,
normalize=False)