Run the Bank Marketing Training | Score dataset using bank marking data | Open Analytics Framework - Run the Bank Marketing Training - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905
In this example, specify the following:
  • The data argument, so you can specify the input teradataml DataFrame that points to the test data table.
  • The data_partition_column argument with the p_id variable defined earlier.
  • The apply_command argument to call the Python 3 interpreter in your user environment and execute your script.
  • The returns argument with the list of output variables and types returned by the script (see Python Training Script). The script shows a single column is written to stdout; the single column model is defined with type BLOB as a returns argument.
  1. Call to the Apply class.
    from teradataml import Apply
    display.print_sqlmr_query = True
    apply_obj = Apply(data=bank_df_train,
                     data_partition_column="partition_column_1",
                     apply_command='python3 bank-marketing-train.py',
                     returns={"model" : BLOB()}
                    )
    model = apply_obj.execute_script()

    Out:

    SELECT * FROM Apply(
    	ON "ALICE"."ml__select__1714118229522254" AS "input"
    	PARTITION BY "partition_column_1"
    	returns(model BLOB)
    	USING
    	APPLY_COMMAND('python3 bank-marketing-train.py')
    	ENVIRONMENT('bank-marketing-env')
    	STYLE('csv')
    	delimiter(',') 
    ) as sqlmr
  2. Deploy the model in the user environment inside Vantage.
    If you skip specifying a custom string with the model_file_prefix argument, a random prefix string will be assigned to the model file.

    The statement output shows the resulting model filename comprises of the user-specified prefix string followed by an underscore character ("_"). This is the filename you will need to use in your Python scoring script to access the model for the scoring task; see the model_file_name variable assignment statement in the script of step 1 in Scoring the Prediction Model.

    apply_obj.deploy(model_column="model", model_file_prefix="xgb_model")

    Out:

    File 'xgb_model_' installed successfully in the remote user environment 'bank-marketing-env'.
    ['xgb_model_']
  3. View the file in the user environment service.
    bank_marketing_env.files

    Out:

    	File	Size	Timestamp
    0	xgb_model_	263123	2024-04-26T07:27:40Z
    1	bank-marketing-predict.py	1454	2024-04-26T07:18:52Z
    2	bank-marketing-train.py	1141	2024-04-26T07:18:51Z