Running Keras Script with APPLY Table Operator | Predicting Next Value using Keras | Teradata Open Analytics Framework - Run the Keras Script with APPLY Table Operator - Teradata VantageCloud Lake

Lake - Analyze Your Data with ClearScape Analytics™

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2026-02-20
dita:mapPath
tcl1683670667798.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
tcl1683670667798
Use the Apply class to create a teradataml Apply class object with the characteristics you want to consider for the call to the APPLY Table Operator.
In this example, specify the following:
  • The apply_command argument to call the Python interpreter in your user environment and execute your script.
  • The returns argument with the list of output variables and types returned by your script.
  • The env_name argument to specify your user environment handler.
  1. Call to the Apply class.
    apply_obj = Apply(data=test_data,
                      apply_command='python3 keras.py',
                      returns={"OUTPUT": FLOAT},
                      env_name=demo_env,
                      style='csv',
                      )
    You can print on screen the SQL query submitted by teradataml in the background with the following statement:
    display.print_sqlmr_query = True
  2. Invoke the execute_script method of the Apply class object to run the Python script inside the user environment.
    apply_obj.execute_script().head(n=5)

    Observe that after running the python statement, the system prints for you the corresponding SQL query as requested.

    SELECT * FROM apply (
      on (SELECT text from sample_dataSet_py) as "input"
      partition by text
      returns (output float)
      using
        environment('py_keras_env')
        apply_command('python3 keras.py')
        style('csv')
    ) as dt;

    Out:

    OUTPUT
    ---------------------------------------------------------------------------
     1.10875667714961E-007
     2.26244948699866E-013
     2.86314182350653E-015
     2.86314182350653E-015
     1.77759042045601E-015
     1.60488906042651E-015
     1.60488906042651E-015
     1.60488906042651E-015
     1.54937790924120E-015
     1.60488906042651E-015