Example: Using td_pmml_predict() function | Teradata Package for R - Example: Using td_pmml_predict() Function - Teradata Package for R

Teradata® Package for R User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for R
Release Number
17.20
Published
March 2024
Language
English (United States)
Last Update
2024-04-09
dita:mapPath
efv1707506846369.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
nqx1518630623256
Product Category
Teradata Vantage
This example scores the data on Vantage using a GLM model generated outside of Vantage.

The example performs prediction using td_pmml_predict_sqle() function using this GLM model in PMML format generated by open source model. Corresponding values are specified for the "overwrite.cached.models". This will erase entire cache.

Both functions with and without "_sqle" are alias. You can use them interchangeably.
  1. Example setup.
    1. Get the current context (connection).
      con <- td_get_context()$connection
    2. Load example data.
      loadExampleData("pmmlpredict_example", "iris_test")
    3. Create tbl_teradata object.
      iris_test <- tbl(con, "iris_test")
    4. Set install location of BYOM functions.
      options(byom.install.location = "mldb")
    5. Check the list of available analytic functions.
      display_analytic_functions(type="BYOM")
  2. Create the following table on Vantage if it does not exist.
    crt_tbl <- "CREATE SET TABLE byom_models(model_id VARCHAR(40), model BLOB)
                PRIMARY INDEX (model_id);"
    DBI::dbExecute(con, sql(crt_tbl))
  3. Load the model.
    Run the following query through BTEQ or Teradata Studio™ to load the models.
     .import vartext file load_byom_model.txt
     .repeat *
     USING (c1 VARCHAR(40), c2 BLOB AS DEFERRED BY NAME) INSERT INTO byom_models(:c1, :c2);
    load_byom_model and BYOM files can be found under inst/scripts in tdplyr installation directory. This file and the BYOM models should be loaded in the same directory.
  4. Retrieve the model.
    modeldata <- tbl(con, "byom_models") %>% filter(model_id=='iris_db_glm_model')
  5. Perform scoring.
    result <- td_pmml_predict_sqle(
                    modeldata = modeldata,
                    newdata = iris_test,
                    accumulate = c('id', 'sepal_length', 'petal_length'),
                    overwrite.cached.models = '*',
                    )
  6. Print the results.
    print(result$result)