Model Export to Python Script
When you export models to Python, a *.py file is generated for each output, as well as a file containing the call as an example(ModelEvaluationExample.py). Depending on the export type, other files are also generated.
The Python script does not use ASCMO code and is therefore independent of an ASCMO installation.
For a model output with the name Y1, the Python class predict_Y1.py, a MAT file predict.mat and the file ModelEvaluationExample.py are created.
The export to a Python class is necessary if you are interested in further output values in addition to the model prediction:
- Sigma (standard deviation) of the model prediction
- Gradient of the model prediction
- Gradient of the Sigma
- Model validity (Valid Model Range)
The gradient is needed, for example, if you want to use a gradient optimizer with the models.
When you export a model with the Model Prediction, Gradient, Hessian, Sigma, Sigma Gradient, and Validity type, the exported MAT files can be very large because a large matrix is required.
For a model output named Y1, the script predict_Y1.py and a file predict_Y1.mat are created.
Model Prediction
from numpy import array, NANimport scipy.io
from predict_Y1 import *
xtest = array ([[0.3, 7.5, 100, 66.1]])
M = predict_Y1()
[Y] = M.modelval(xtest)
from numpy import array, NAN
import scipy.io
from predict_Y1 import *
xtest = array ([[0.3, 7.5, 100, 66.1]])
M = predict_Y1()
[Y, Ygrad, Yhessian, Ystd1, Ystd2, Ystd1_grad, Ystd2_grad, YstdGradNoBoxCoxTrans, Validity] = M.modelval_ygrad_std(xtest)
Note |
---|
The Python installation must contain the packages NumPy and SciPy. |