Teradata Package for Python Function Reference - DecisionTree - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
DecisionTree

 
Functions
       
DecisionTree(data, columns, response_column, algorithm='gainratio', binning=False, exclude_columns=None, max_depth=100, num_splits=None, operator_database=None, pruning=None)
DESCRIPTION:
    The Gain Ratio Extreme Decision Tree function performs decision tree modeling and returns
    a teradataml DataFrame containing one row with two columns. The second column contains an
    XML string representing the resulting decision tree model described in Predictive Model
    Markup Language (PMML).
 
PARAMETERS:
    data:
        Required Argument.
        Specifies the input data to be used for decision tree modeling.
        Types: teradataml DataFrame
 
    columns:
        Required Argument.
        Specifies the name(s) of the column(s) to be used in decision tree building.
        Occasionally, it can also accept permitted strings to specify all columns, all
        numeric columns or all character columns.
        Permitted Values:
            * Name(s) of the column(s) in "data".
            * Pre-defined strings:
                * 'all' - all columns
                * 'allnumeric' - all numeric columns
                * 'allcharacter' - all character columns
        Types: str OR list of Strings (str)
 
    response_column:
        Required Argument.
        Specifies the name of a column whose values are being predicted.
        Types: str
 
    algorithm:
        Optional Argument.
        Specifies the name of the algorithm that the decision tree uses during building.
        Permitted Values: "gainratio"
        Default Value: "gainratio"
        Types: str
 
    binning:
        Optional Argument.
        Specifies whether to perform binning on the continuous independent variables
        automatically. When set to True, continuous data is separated into one hundred
        bins. If the column has fewer than one hundred distinct values, this argument
        is ignored.
        Default Value: False
        Types: bool
 
    exclude_columns:
        Optional Argument.
        Specifies the name(s) of the column(s) to exclude from the decision tree building.
        If 'all', 'allnumeric' or 'allcharacter' is used in the "columns" argument, this
        argument can be used to exclude specific columns from tree building.
        Types: str OR list of Strings (str)
 
    max_depth:
        Optional Argument.
        Specifies the maximum number of levels the tree can grow.
        Default Value: 100
        Types: int
 
    num_splits:
        Optional Argument.
        Specifies how far the decision tree can be split. Unless a node is pure (meaning
        it has only observations with the same dependent value) it splits if each branch
        that can come off this node contains at least this many observations. The default
        is a minimum of two cases for each branch.
        Types: int
 
    operator_database:
        Optional Argument.
        Specifies the database where the table operators called by Vantage Analytic Library
        reside. If not specified, the library searches the standard search path for table
        operators, including the current database.
        Types: str
 
    pruning:
        Optional Argument.
        Specifies the style of pruning to use after the tree is fully built.
        Permitted Values: "gainratio", "none" (no pruning)
        Default Value: "gainratio"
        Types: str
 
RETURNS:
    An instance of DecisionTree.
    Output teradataml DataFrames can be accessed using attribute references, such as
    DecisionTreeObj.<attribute_name>.
    Output teradataml DataFrame attribute name is: result.
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
EXAMPLES:
    # Notes:
    #   1. To execute Vantage Analytic Library functions,
    #       a. import "valib" object from teradataml.
    #       b. set 'configure.val_install_location' to the database name where Vantage
    #          analytic library functions are installed.
    #   2. Datasets used in these examples can be loaded using Vantage Analytic Library
    #      installer.
    # Import valib object from teradataml to execute this function.
    from teradataml import valib
 
    # Set the 'configure.val_install_location' variable.
    from teradataml import configure
    configure.val_install_location = "SYSLIB"
 
    # Create the required teradataml DataFrame.
    df = DataFrame("customer_analysis")
    print(df)
 
    # Run DecisionTree() on columns "age", "income" and "nbr_children", with dependent
    # variable "gender".
    obj = valib.DecisionTree(data=df,
                             columns=["age", "income", "nbr_children"],
                             response_column="gender",
                             algorithm="gainratio",
                             binning=False,
                             max_depth=5,
                             num_splits=2,
                             pruning="gainratio")
 
    # Print the results.
    print(obj.result)