td_save_model() | Teradata R Package - 17.00 - td_save_model() - Teradata R Package

Teradata® R Package User Guide

prodname
Teradata R Package
vrm_release
17.00
created_date
November 2020
category
User Guide
featnum
B700-4005-090K

The td_save_model() function allows a user to save model related information to the Model Catalog, and also persist the model's output tbl_teradata objects to tables on Vantage (which would have otherwise been purged at the end of the session), without having to call the copy_to() function.

This allows the user to create a connection anytime later using a fresh tdplyr (or even a SQL) session to use the saved models in workflows.

For example, a user can create a GLM model using the ML Engine GLM function (td_glm_mle), and then save this model by calling the td_save_model() function.

The td_save_model() function persists not only the model's result tbl_teradata objects, but also all the arguments to the model generating function and some other details as mentioned below, so that a user can understand how the model is generated:
  • The target column from the training data input to the model, when available.
    The target column is currently saved only for the functions that use formula, and when the formula is used, in case it is optional.
  • The prediction type for the function: CLASSIFICATION, REGRESSION, CLUSTERING, or OTHER.
  • The engine used to generate the model: ML Engine, or Advanced SQL Engine.
  • The client language used to generate the model: tdplyr.
  • The name of the algorithm associated with the function.
  • The time in seconds required to run the model generating function.
  • The model creating user's name.
  • The status and access level of the model (see the td_publish_model() section).
  • The location where the model is stored: Advanced SQL Engine.
  • The date and time when the model is saved.
  • If possible, the name of the table corresponding to the tbl_teradata objects passed as input to the model generating function along with their dimensions.
  • The user provided optional arguments model.project, entity.target, and performance.metrics.

Once the model is saved, all of this information is available in the output of td_describe_model().

A model can be saved only by its creator.
Required arguments:
  • model specifies the tdplyr analytic function model to be saved;
  • name specifies the unique name to identify the model to be saved;
  • description specifies a note describing the model to be saved.
Optional arguments:
  • model.project specifies the project that the model is associated with;
  • entit.target specifies a group or team that the model is associated with;
  • performance.metrics specifies the performance metrics for the model.

    It must be a named list of the form list(<metric> = list(measure = <value>), ...).

    For example: list(AUC = list(measure = 0.5), ...).

Example

  • Load example data.
    > loadExampleData("glm_example", "admissions_train")
  • Create object of class "tbl_teradata" to use as input.
    > admissions_train <- tbl(con, "admissions_train")
  • Create the GLM model.
    > td_glm_out1 <- td_glm_mle(formula = (admitted ~ stats + masters + gpa + programming),
                                family = "LOGISTIC",
                                linkfunction = "LOGIT",
                                data = admissions_train,
                                weights = "1",
                                threshold = 0.01,
                                maxit = 25,
                                step = FALSE,
                                intercept = TRUE
      )
  • Save the generated model.
    > td_save_model(model = td_glm_out1, name = "glm_model", description = "GLM test")
    Persisting model information.
    Persisted table: "alice".r__t__sqlmr_stdout_1594617222690011
    Persisted table: "alice".r__t__td_glm_mle0_1594617222126955
    Successfully persisted model.

    As the output message suggests, the model is saved successfully.