Teradata Package for Python Function Reference | 17.10 - DecisionForestPredict - 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.10
Published
April 2022
Language
English (United States)
Last Update
2022-08-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
DecisionForestPredict

 
Functions
       
DecisionForestPredict(object=None, newdata=None, id_column=None, detailed=False, terms=None, newdata_order_column=None, object_order_column=None)
DESCRIPTION:
    The DecisionForestPredict() function uses the model generated by the
    DecisionForest() function to generate predictions on a response variable for a
    test set of data.
    The model can be stored in either a teradataml DataFrame or a DecisionForest object.
 
PARAMETERS:
    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
 
    newdata:
        Required Argument.
        Specifies the name of the teradataml DataFrame containing the
        attribute names and the values.
        Types: teradataml DataFrame
 
    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 forest
        trees; that is, the decision tree and the specific tree information,
        including task index and tree index for each tree.
        Default Value: False
        Types: bool
 
    terms:
        Optional Argument.
        Specifies the names of the newdata columns to copy to the output
        teradataml DataFrame.
        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 table or not.
                When set to True, results are persisted in table; otherwise, results
                are garbage collected at the end of the session.
                Default Value: False
                Types: boolean
 
            volatile:
                Optional Argument.
                Specifies whether to put the results of the function in volatile table or not.
                When set to True, results are stored in volatile table, otherwise not.
                Default Value: False
                Types: boolean
 
        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 DecisionForestPredict.
    Output teradataml DataFrames can be accessed using attribute
    references, such as DecisionForestPredictObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
EXAMPLES:
    # Notes:
    #    1. Get the connection to Vantage, before importing the function in user space.
    #    2. User can import the function, if it is available on the Vantage user is connected to.
    #    3. To check the list of analytic functions available on the Vantage user connected to,
    #       use "display_analytic_functions()"
 
    # Load the example data.
    load_example_data("decisionforestpredict", ["housing_train","housing_test"])
 
    # Create teradataml DataFrame objects.
    housing_test = DataFrame.from_table("housing_test")
    housing_train = DataFrame.from_table("housing_train")
 
    # Check the list of available analytic functions.
    display_analytic_functions()
 
    # Import function DecisionForestPredict
    from teradataml import DecisionForestPredict
 
    # Example 1: Train the data, i.e., create a decision forest Model with "tree_type" as classification.
    formula = "homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl"
    rft_model = DecisionForest(data=housing_train,
                               formula = formula,
                               tree_type="classification",
                               ntree=50,
                               tree_size=100,
                               nodesize=1,
                               variance=0.0,
                               max_depth=12,
                               maxnum_categorical=20,
                               mtry=3,
                               mtry_seed=100,
                               seed=100
                               )
 
    # Run predict on the output of decision forest.
    decision_forest_predict_out = DecisionForestPredict(object = rft_model,
                                                        newdata = housing_test,
                                                        id_column = "sn",
                                                        detailed = False,
                                                        terms = ["homestyle"]
                                                        )
 
    # Print the result DataFrame.
    print(decision_forest_predict_out.result)