Teradata Package for Python Function Reference | 20.00 - SVMSparsePredict - 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 - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00.00.03
Published
December 2024
ft:locale
en-US
ft:lastEdition
2024-12-19
dita:id
TeradataPython_FxRef_Enterprise_2000
Product Category
Teradata Vantage
 
 
TDDecisionForestPredict

 
Functions
       
TDDecisionForestPredict(newdata=None, object=None, id_column=None, detailed=False, output_prob=False, output_responses=None, accumulate=None, **generic_arguments)
DESCRIPTION:
    TDDecisionForestPredict() function uses the model output by DecisionForest()
    function to analyze the input data and make predictions. This function outputs
    the probability that each observation is in the predicted class.
 
    Processing times are controlled by the number of trees in the model.
    When the number of trees is more than what can fit in memory, then
    the trees are cached in a local spool space.
 
 
PARAMETERS:
    newdata:
        Required Argument.
        Specifies the teradataml DataFrame containing the input data.
        Types: teradataml DataFrame
 
    object:
        Required Argument.
        Specifies the teradataml DataFrame which contains the model data generated by
        the DecisionForest() function or instance of DecisionForest.
        Types: teradataml DataFrame or DecisionForest
 
    id_column:
        Required Argument.
        Specifies a column containing a unique identifier for each test point
        in the test set.
        Types: str
 
    detailed:
        Optional Argument.
        Specifies whether to output detailed information about the decision
        tree and the specific tree information, including task index and
        tree index for each tree.
        Default Value: False
        Types: bool
 
    output_prob:
        Optional Argument.
        Specifies whether to output probability for each response.
        Notes:
            * If "output_prob" is false the function outputs only
              the probability of the predicted class.
            * The "output_prob" must be true when using "output_responses".
            * The "output_prob" only works with a classification model.
        Default Value: False
        Types: bool
 
    output_responses:
        Optional Argument.
        Specifies the classes to output the probabilities. By default it
        output only the probability of the predicted class.
        Note:
            * The "output_responses" only works with a classification model.
        Types: str OR list of str(s)
 
    accumulate:
        Optional Argument.
        Specifies the name(s) of input teradataml DataFrame column(s) to copy to the
        output. By default, the function copies no input teradataml DataFrame columns
        to the output.
        Types: str OR list of Strings (str)
 
    **generic_arguments:
        Specifies the generic keyword arguments SQLE functions accept. Below
        are the generic keyword arguments:
            persist:
                Optional Argument.
                Specifies whether to persist the results of the
                function in a table or not. When set to True,
                results are persisted in a table; otherwise,
                results are garbage collected at the end of the
                session.
                Default Value: False
                Types: bool
 
            volatile:
                Optional Argument.
                Specifies whether to put the results of the
                function in a volatile table or not. When set to
                True, results are stored in a volatile table,
                otherwise not.
                Default Value: False
                Types: bool
 
        Function allows the user to partition, hash, order or local
        order the input data. These generic arguments are available
        for each argument that accepts teradataml DataFrame as
        input and can be accessed as:
            * "<input_data_arg_name>_partition_column" accepts str or
                list of str (Strings)
            * "<input_data_arg_name>_hash_column" accepts str or list
                of str (Strings)
            * "<input_data_arg_name>_order_column" accepts str or list
                of str (Strings)
            * "local_order_<input_data_arg_name>" accepts boolean
        Note:
            These generic arguments are supported by teradataml if
            the underlying SQLE Engine function supports, else an
            exception is raised.
 
RETURNS:
    Instance of TDDecisionForestPredict.
    Output teradataml DataFrames can be accessed using attribute
    references, such as TDDecisionForestPredictObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
EXAMPLES:
    # Notes:
    #     1. Get the connection to Vantage to execute the function.
    #     2. One must import the required functions mentioned in
    #        the example from teradataml.
    #     3. Function will raise error if not supported on the Vantage
    #        user is connected to.
 
    # Load the example data.
    load_example_data("decisionforest", ["boston"])
    load_example_data("byom", "iris_input")
 
    # Create teradataml DataFrame objects.
    boston = DataFrame.from_table("boston")
    iris_input = DataFrame("iris_input")
 
    # Check the list of available analytic functions.
    display_analytic_functions()
 
    # Example 1 : This example takes boston data as input, and generates the Regression
    #             model using DecisionForest(). Using TDDecisionForestPredict() function
    #             to predict the medv with the Regression model generated by XGBoost().
 
    # Create 2 samples of input data - sample 1 will have 80% of total rows and
    # sample 2 will have 20% of total rows.
    boston_sample = boston.sample(frac=[0.8, 0.2])
 
    # Create train dataset from sample 1 by filtering on "sampleid" and drop
    # "sampleid" column as it is not required for training model.
    boston_train = boston_sample[boston_sample.sampleid == "1"].drop("sampleid", axis = 1)
 
    # Create test dataset from sample 2 by filtering on "sampleid" and
    # drop "sampleid" column as it is not required for scoring.
    boston_test = boston_sample[boston_sample.sampleid == "2"].drop("sampleid", axis = 1)
 
    # Training the model.
    DecisionForest_out = DecisionForest(data = boston_train,
                                        input_columns = ['crim', 'zn', 'indus', 'chas', 'nox', 'rm',
                                                        'age', 'dis', 'rad', 'tax', 'ptratio', 'black',
                                                        'lstat'],
                                        response_column = 'medv',
                                        max_depth = 12,
                                        num_trees = 4,
                                        min_node_size = 1,
                                        mtry = 3,
                                        mtry_seed = 1,
                                        seed = 1,
                                        tree_type = 'REGRESSION')
 
    # TDDecisionForestPredict() predicts the result using generated Regression model by
    # DecisionForest() and "newdata".
    TDDecisionForestPredict_out = TDDecisionForestPredict(newdata=boston_test,
                                                          object=DecisionForest_out,
                                                          id_column="id")
 
    # Print the result DataFrame.
    print(TDDecisionForestPredict_out.result)
 
    # Example 2 : This example takes iris_input data, and generates the Classification
    #             model using DecisionForest(). Using TDDecisionForestPredict() function
    #             to predict the species with the Classification model generated by XGBoost().
    #             Provides the classes for which to output the probabilities.
 
    # Create 2 samples of input data - sample 1 will have 80% of total rows and
    # sample 2 will have 20% of total rows.
    iris_sample = iris_input.sample(frac=[0.8, 0.2])
 
    # Create train dataset from sample 1 by filtering on "sampleid" and drop
    # "sampleid" column as it is not required for training model.
    iris_train = iris_sample[iris_sample.sampleid == "1"].drop("sampleid", axis = 1)
 
    # Create test dataset from sample 2 by filtering on "sampleid" and
    # drop "sampleid" column as it is not required for scoring.
    iris_test = iris_sample[iris_sample.sampleid == "2"].drop("sampleid", axis = 1)
 
    # Training the model.
    DecisionForest_out_2 = DecisionForest(data=iris_train,
                                          input_columns=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'],
                                          response_column="species",
                                          tree_type="CLASSIFICATION")
 
    # TDDecisionForestPredict() predicts the result using generated Regression model by
    # DecisionForest() and "newdata".
    TDDecisionForestPredict_out_2 = TDDecisionForestPredict(newdata=iris_test,
                                                            object=DecisionForest_out_2,
                                                            id_column="id",
                                                            output_prob=True,
                                                            output_responses=['1', '2', '3'])
 
    # Print the result DataFrame.
    print(TDDecisionForestPredict_out_2.result)