ONNXPredict performs a prediction on each row of the input table using a model previously trained in ONNX and then loaded into the database. The model uses an interchange format called as ONNX and it is loaded to the database in Vantage in a table by the user as a blob.
The following are examples of ONNXPredict() function call.
Example Setup
- Import necessary modules.
>>> import os, teradataml
>>> from teradataml.options.configure import configure
>>> from teradataml import DataFrame, load_example_data, save_byom, retrieve_byom
- Load example data.
>>> load_example_data("byom", "iris_test")
- Create teradataml DataFrame object.
>>> iris_test = DataFrame("iris_test")
- Set install location of the BYOM functions.
>>> configure.byom_install_location = "mldb"
Example 1: Predict the flower species using trained 'skl_model' model
- Load model file into Vantage.
>>> model_file_path = os.path.join(os.path.dirname(teradataml.__file__), "data", "models")
>>> skl_model_file = os.path.join(model_file_path, "iris_db_dt_model_sklearn.onnx")
- Save the model.
>>> save_byom("iris_db_dt_model_sklearn", skl_model_file, "byom_models")
- Retrieve model.
>>> skl_model = retrieve_byom("iris_db_dt_model_sklearn", table_name="byom_models")
- Using ONNXPredict to score data.
>>> ONNXPredict_out = ONNXPredict(accumulate="id", newdata=iris_test, modeldata=skl_model)