retrieve_model() | Teradata Python Package - 17.00 - retrieve_model() - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Release Date
November 2021
Content Type
User Guide
Publication ID
B700-4006-070K
Language
English (United States)

The retrieve_model() API allows a user to recreate a teradataml Analytic Function object from the information saved with the Model Catalog using save_model(). This analytic function object can then be used in the user’s workflow.

For example, if a user has built a user-base classification model, he or she can save the information related to this model and reuse it at every instance when there is need to score a new set of user data.

The required argument name, which is also the only argument, specifies the name of the model to retrieve.

A user can only retrieve the models he or she has access to.

Example Prerequisites

Follow the steps in save_model() to create a classification tree model that can be input to DecisionForestPredict and save the generated model.

Example

  • View the saved models.
    >>> list_models()
                   ModelName  ModelAlgorithm ModelGeneratingEngine ModelGeneratingClient CreatedBy                 CreatedDate
    0  decision_forest_model  DecisionForest             ML Engine            teradataml     ALICE  2020-05-17 23:59:48.740000
  • Retrieve the saved model.
    >>> # Retrieve the saved model
    >>> retrieved_rft_model = retrieve_model("decision_forest_model")
  • Use the retrieved model in predict.
    >>> # Use the retrieved model in predict.
    >>> decision_forest_predict_out = DecisionForestPredict(object = retrieved_rft_model,
                                                            newdata = housing_test,
                                                            id_column = "sn",
                                                            detailed = False,
                                                            terms = ["homestyle"],
                                                            newdata_order_column=['sn', 'price'],
                                                            object_order_column=['worker_ip', 'task_index']
                                                           )
  • Print the result.
    >>> # Print the results.
    >>> print(decision_forest_predict_out.result)
    ############ STDOUT Output ############
     
      homestyle   sn prediction  confidence_lower  confidence_upper
    0   Classic  260    Classic              0.90              0.90
    1   Classic   13    Classic              0.98              0.98
    2   Classic  142    Classic              0.86              0.86
    3  Eclectic   53   Eclectic              0.98              0.98
    4  Eclectic   38   Eclectic              0.90              0.90
    5   Classic  111    Classic              0.96              0.96
    6   Classic  251    Classic              0.76              0.76
    7  Eclectic  408   Eclectic              0.96              0.96
    8   Classic   16    Classic              0.90              0.90
    9   Classic  132    Classic              0.92              0.92