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

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

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)