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.
- Example setup.
- Get the current context (connection).
con <- td_get_context()$connection
- Load example data.
loadExampleData("pmmlpredict_example", "iris_test")
- Create tbl_teradata object.
iris_test <- tbl(con, "iris_test")
- Set install location of BYOM functions.
options(byom.install.location = "mldb")
- Check the list of available analytic functions.
display_analytic_functions(type="BYOM")
- Get the current context (connection).
- 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))
- 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. - Retrieve the model.
modeldata <- tbl(con, "byom_models") %>% filter(model_id=='iris_db_glm_model')
- Perform scoring.
result <- td_pmml_predict_sqle( modeldata = modeldata, newdata = iris_test, accumulate = c('id', 'sepal_length', 'petal_length'), overwrite.cached.models = '*', )
- Print the results.
print(result$result)