Running Keras Script with APPLY Table Operator | Predicting Next Value using Keras | Open Analytics Framework on VantageCloud Lake - Running Keras Script with APPLY Table Operator - 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

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;
    The output:
    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