DataikuPredict | Supported External Model Types | Teradata Package for Python - DataikuPredict - 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-10-10
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
lifecycle
latest
Product Category
Teradata Vantage

Use the DataikuPredict() function to score data in Vantage with a model that has been created outside Vantage and exported to Vantage using Dataiku format.

Required Arguments:
  • modeldata: Specifies the model teradataml DataFrame to be used for scoring.
  • newdata: Specifies the input teradataml DataFrame that contains the data to be scored.
  • accumulate: Specifies the names of input teradataml DataFrame columns to copy to the output.

    By default, the function copies all input teradataml DataFrame columns to the output.

Optional Arguments:
  • model_output_fields: Specifies the columns of the json output that the user wants to specify as individual columns instead of the entire json report.
  • overwrite_cached_models: Specifies the model name that needs to be removed from the cache.

    If a model loaded into the memory of the node fits in the cache, it stays in the cache until being evicted to make space for another model that needs to be loaded. Therefore, a model can remain in the cache even after the completion of function call. Other functions that use the same model can use it, saving the cost of reloading it into memory.

    You may overwrite a cached model only when it has been updated, to make sure that the Predict function uses the updated model instead of the cached model.

    Do not use the overwrite_cached_models argument except when trying to replace a previously cached model. This applies to any model type (PMML, H2O Open Source, DAI, ONNX, and Dataiku). Using this argument in other cases, including in concurrent queries or multiple times within a short period of time, may lead to an OOM error from garbage collection not being fast enough.

    Permitted values 'current_cached_model', '*', 'true', 't', 'yes', '1', 'false', 'f', 'no', 'n', or '0'.

    Default Values is "false", which means this function does not overwrite cached models.

  • is_debug: Specifies whether debug statements are added to a trace table or not.

    When set to True, debug statements are added to a trace table that must be created beforehand.

    Default value is False.

    • Only available with BYOM version 3.00.00.02 and later.
    • Teradata recommends using small data input sizes, since a database trace table is used to collect the debug information which does impact performance of the function.
    To generate this log:
    1. Create a global trace table with columns vproc_ID BYTE(2), Sequence INTEGER, Trace_Output VARCHAR(31000).
    2. Turn on session function tracing:
      SET SESSION FUNCTION TRACE USING '' FOR TABLE <trace_table_name_created_in_step_1>;
    3. Execute function with is_debug set to 'True'.
    4. Debug information is logged to the table created in step 1.
    5. To turn off the logging, either disconnect from the session or run the following SQL:
      SET SESSION FUNCTION TRACE OFF;
    The trace table is temporary and the information is deleted if you log off from the session. If long term persistence is necessary, you can copy the table to a permanent table before leaving the session.

This function returns an instance of DataikuPredict. Output teradataml DataFrame can be accessed using attribute references, such as DataikuPredictObj.<attribute_name>. Output teradataml DataFrame attribute name is: result.

Example Setup

  • You need to get the connection to Vantage to run this function. And the function will raise error if it is not supported on the Vantage you are connected to.
  • To run BYOM functions, you need to set configure.byom_install_location to the database name where BYOM functions are installed.
  • Import required libraries and functions.
    import os, teradataml
    from teradataml import get_connection, DataFrame
    from teradataml import load_example_data, save_byom, retrieve_byom
    from teradataml import configure, display_analytic_functions, execute_sql
  • Load example data.
    load_example_data("byom", "iris_test")
  • Create teradataml DataFrame object.
    iris_test = DataFrame.from_table("iris_test")
  • Set install location of the BYOM functions.
    configure.byom_install_location = "mldb"
  • Check available analytic functions.
    display_analytic_functions(type="BYOM")
  • Load model file into Vantage.
    model_file = os.path.join(os.path.dirname(teradataml.__file__), "data",
                              "models", "dataiku_iris_data_ann_thin")
    save_byom("dataiku_iris_data_ann_thin", model_file, "byom_models")
  • Retrieve model.
    modeldata = retrieve_byom("dataiku_iris_data_ann_thin", table_name="byom_models")

Example 1: Score data in Vantage with a model created outside Vantage

  • Run the predict function to score data.
    DataikuPredict_out_1 = DataikuPredict(newdata=iris_test,
                                                  modeldata=modeldata,
                                                  accumulate=['id', 'sepal_length', 'petal_length'],
                                                  overwrite_cached_models="*")
  • Print the result.
    print(DataikuPredict_out_1.result)

Example 2: View trace table information

  • Create the trace table.
    crt_tbl_query = 'CREATE GLOBAL TEMPORARY TRACE TABLE BYOM_Trace \
                    (vproc_ID  BYTE(2) \
                    ,Sequence  INTEGER \
                    ,Trace_Output VARCHAR(31000) CHARACTER SET LATIN NOT CASESPECIFIC) \
                    ON COMMIT PRESERVE ROWS;'
    execute_sql(crt_tbl_query
  • Turn on the session function.
    execute_sql("SET SESSION FUNCTION TRACE USING '' FOR TABLE BYOM_Trace;")
  • Run the DataikuPredict() function using is_debug=True.
    DataikuPredict_out_2 = DataikuPredict(newdata=iris_test,
                                          modeldata=modeldata,
                                          accumulate=['id', 'sepal_length', 'petal_length'],
                                          overwrite_cached_models="*",
                                          is_debug=True)
  • Print the result.
    print(DataikuPredict_out_2.result)
  • View the trace table information.
    trace_df = DataFrame.from_table("BYOM_Trace")
    print(trace_df)
  • Turn off the session function.
    execute_sql("SET SESSION FUNCTION TRACE OFF;")