Using Teradata Vantage Analytic Functions with Teradata Python Package

Teradata® Python Package User Guide

brand
Teradata Vantage
prodname
Teradata Python Package
vrm_release
16.20
category
User Guide
featnum
B700-4006-098K

Teradata Python Package provides a Python interface to all of the analytic functions in the Teradata Vantage: ML Engine analytic functions and SQL Engine in-database analytic functions.

The teradataml analytics package includes two subpackages:
  • teradataml.analytics.mle
  • teradataml.analytics.sqle
All teradataml analytic functions are in either of these two subpackages.
Teradata recommends importing the desired analytic function in one of the following two ways:
  • For best practice, import from the teradataml package.
    For example:
    # import DecisionTreePredict from the teradataml package (recommended)
    from teradataml import DecisionTreePredict
  • To choose the engine where the analytic function is used, import from the desired subpackage.
    For example:
    # import DecisionTreePredict from the teradataml.analytics.sqle package
    from teradataml.analytics.sqle import DecisionTreePredict

Older versions of teradataml placed all analytic functions in a single package (teradataml.analytics), with each analytic function in it’s own module.

From release 16.20.00.01, the analytic functions are in either of the two subpackages above, with each analytic function in it’s own module.

Instead of using the old modules in the teradataml.analytics package, Teradata recommends importing the desired analytic function in one of the ways listed above.

Instantiating an analytical function from the old module in the teradataml.analytics package gives a DeprecationWarning.

For example:
>>> from teradataml.analytics.KMeans import KMeans
>>> KMeans(*args, **kw)
 
DeprecationWarning:
The "teradataml.analytics.KMeans.KMeans" class has moved to a new package in version 16.20.0.1.
Import from the teradataml package, teradataml.analytics package, or directly from the teradataml.analytics.mle.KMeans module.
See the teradataml 16.20.0.1 User Guide for more information.

This section shows examples of how the Teradata Python Package enables users to run a selection of these analytic functions through a Python interface.

In this section, assume you have the connection to the Teradata Vantage SQL Engine as user "tdapUser", where the target database is "tdapUserDB".

See Testing Connection to the Database for details on how to set up a connection and import the teradataml module.