ONNXPredict | Supported External Model Types | Teradata Package for Python - ONNXPredict - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-09
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
Product Category
Teradata Vantage

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)