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

 
teradataml.analytics.mle.XGBoostPredict = class XGBoostPredict(builtins.object)
     Methods defined here:
__init__(self, object=None, newdata=None, id_column=None, terms=None, iter_num=None, num_boosted_trees=None, attribute_name_column=None, attribute_value_column=None, output_response_probdist=False, output_responses=None, newdata_sequence_column=None, object_sequence_column=None, newdata_partition_column='ANY', newdata_order_column=None, object_order_column=None)
DESCRIPTION:
    The XGBoostPredict function applies the model output by the XGBoost
    function to a new data set, outputting predicted labels for each data
    point.
 
 
PARAMETERS:
    object:
        Required Argument.
        Specifies the teradataml DataFrame containing the model data.
 
    object_order_column:
        Required Argument.
        Specifies Order By columns for object.
        Values to this argument can be provided as list, if multiple columns
        are used for ordering.
        Types: str OR list of Strings (str)
 
    newdata:
        Required Argument.
        Specifies the teradataml DataFrame containing the input test data.
 
    newdata_partition_column:
        Optional Argument.
        Specifies Partition By columns for newdata.
        Values to this argument can be provided as list, if multiple columns
        are used for partition.
        Default Value: ANY
        Types: str OR list of Strings (str)
 
    newdata_order_column:
        Optional Argument.
        Specifies Order By columns for newdata.
        Values to this argument can be provided as list, if multiple columns
        are used for ordering.
        Types: str OR list of Strings (str)
 
    id_column:
        Optional Argument.
        Specifies a column containing a unique identifier for each test point
        in the test set.
        Types: str
 
    terms:
        Optional Argument.
        Specifies the names of the input columns to copy to the output table.
        Types: str OR list of Strings (str)
 
    iter_num:
        Optional Argument.
        Specifies the number of iterations for each boosted tree to use for
        prediction. The lower bound is 1. If this argument is not specified,
        the value is the same as used for training model. The number of
        iterations used is upper bounded by the number of iterations used
        during training.
        Types: int
 
    num_boosted_trees:
        Optional Argument.
        Specifies the number of boosted trees to be used for prediction. If
        this argument is not specified, the value is the same as used for
        training model. The number of boosted trees used for prediction is
        upper bounded by the number of boosted trees used during training.
        Types: int
 
    attribute_name_column:
        Optional Argument.
        Required for sparse data format, if the data set is in sparse format,
        this argument indicates the column containing the attributes in the
        input teradataml DataFrame.
        Types: str
 
    attribute_value_column:
        Optional Argument.
        If the data is in the sparse format, this argument indicates the
        column containing the attribute values in the input teradataml DataFrame.
        Types: str
 
    output_response_probdist:
        Optional Argument.
        Specifies whether to output probabilities or not.
        Note: "output_response_probdist" argument support is only available
              when teradataml is connected to Vantage 1.1.1 or later.
        Default Value: False
        Types: bool
 
    output_responses:
        Optional Argument.
        Specifies the responses in the input teradataml DataFrame.
        output_response_probdist must be set to True in order to use this argument.
        Note: "output_responses" argument support is only available
              when teradataml is connected to Vantage 1.1.1 or later.
        Types: str OR list of Strings (str)
 
    newdata_sequence_column:
        Optional Argument.
        Specifies the list of column(s) that uniquely identifies each row of
        the input argument "newdata". The argument is used to ensure
        deterministic results for functions which produce results that vary
        from run to run.
        Types: str OR list of Strings (str)
 
    object_sequence_column:
        Optional Argument.
        Specifies the list of column(s) that uniquely identifies each row of
        the input argument "object". The argument is used to ensure
        deterministic results for functions which produce results that vary
        from run to run.
        Types: str OR list of Strings (str)
 
RETURNS:
    Instance of XGBoostPredict.
    Output teradataml DataFrames can be accessed using attribute
    references, such as XGBoostPredictObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException
 
 
EXAMPLES:
    # Load example data.
    load_example_data("xgboost", ["housing_train_binary","iris_train","sparse_iris_train","sparse_iris_attribute"])
    load_example_data("xgboostpredict", ["housing_test_binary", "iris_test", "sparse_iris_test"])
 
    # Example 1 - Binary Classification: Predict the housing style (classic or eclectic)
    # Create teradataml DataFrame objects.
    housing_train_binary = DataFrame.from_table("housing_train_binary")
    housing_test_binary = DataFrame.from_table("housing_test_binary")
 
    # Generate the XGBoost model, on the housing data, that contains couple of labels
    # classic and eclectic, which specify the housing style based on the 12 other
    # attributes of the house, such as bedrooms, stories, price etc.
    XGBoostOut1 = XGBoost(data=housing_train_binary,
                          id_column='sn',
                          formula="homestyle ~ driveway + recroom + fullbase + gashw + airco + prefarea + price + lotsize + bedrooms + bathrms + stories + garagepl",
                          num_boosted_trees=2,
                          loss_function='binomial',
                          prediction_type='classification',
                          reg_lambda=1.0,
                          shrinkage_factor=0.1,
                          iter_num=10,
                          min_node_size=1,
                          max_depth=10
                          )
 
    # Use the generated model to find predict the house style, on the test data.
    XGBoostPredictOut1 = XGBoostPredict(newdata=housing_test_binary,
                                        object=XGBoostOut1,
                                        object_order_column=['tree_id', 'iter', 'class_num'],
                                        id_column='sn',
                                        terms='homestyle',
                                        num_boosted_trees=1
                                        )
 
    # Print the results
    print(XGBoostPredictOut1)
 
    # Example 2: Multiple-Class Classification: Predict the Iris flower species
    #                                           (setosa, virginica or versicolor).
    iris_train = DataFrame.from_table("iris_train")
    iris_test = DataFrame.from_table("iris_test")
 
    # Generate the model on one of the famous dataset Iris Data set, that contains 50 samples
    # from three species of Iris flower setosa, virginica and versicolor. Each data point contains
    # measurements of length and width of sepals and petals.
    XGBoostOut2 = XGBoost(data=iris_train,
                         id_column='id',
                          formula="species ~ sepal_length + sepal_width + petal_length + petal_width ",
                          num_boosted_trees=2,
                          loss_function='softmax',
                          reg_lambda=1.0,
                          shrinkage_factor=0.1,
                          iter_num=10,
                          min_node_size=1,
                          max_depth=10)
 
    # Use the generated model to predict the Iris flower type.
    XGBoostPredictOut2 = XGBoostPredict(newdata=iris_test,
                        newdata_partition_column='id',
                        object=XGBoostOut2,
                        object_order_column=['tree_id', 'iter','class_num'],
                        id_column='id',
                        terms='species',
                        num_boosted_trees=2
                        )
 
    # Print the results
    print(XGBoostPredictOut2)
 
    # Example 3: Sparse Input Format. response_column argument is specified instead of formula.
    sparse_iris_train = DataFrame.from_table("sparse_iris_train")
    sparse_iris_test = DataFrame.from_table("sparse_iris_test")
    sparse_iris_attribute = DataFrame.from_table("sparse_iris_attribute")
 
    # Generate the model
    XGBoostOut3 = XGBoost(data=sparse_iris_train,
                      attribute_table=sparse_iris_attribute,
                      id_column='id',
                      response_column='species',
                      prediction_type='classification',
                      attribute_name_column='attribute',
                      attribute_value_column='value_col',
                      num_boosted_trees=2,
                      loss_function='SOFTMAX',
                      reg_lambda=1.0,
                      shrinkage_factor=0.1,
                      iter_num=10,
                      min_node_size=1,
                      max_depth=10)
 
    # Use the generated model to find prediction.
    XGBoostPredictOut3 = XGBoostPredict(object = XGBoostOut3,
                                        object_order_column = ["tree_id", "iter", "class_num"],
                                        newdata = sparse_iris_test,
                                        newdata_partition_column = ["id"],
                                        id_column = "id",
                                        terms = ["species"],
                                        num_boosted_trees = 2,
                                        attribute_name_column = "attribute",
                                        attribute_value_column = "value_col"
                                        )
 
    # Print the results
    print(XGBoostPredictOut3)
__repr__(self)
Returns the string representation for a XGBoostPredict class instance.
get_build_time(self)
Function to return the build time of the algorithm in seconds.
When model object is created using retrieve_model(), then the value returned is 
as saved in the Model Catalog.
get_prediction_type(self)
Function to return the Prediction type of the algorithm.
When model object is created using retrieve_model(), then the value returned is 
as saved in the Model Catalog.
get_target_column(self)
Function to return the Target Column of the algorithm.
When model object is created using retrieve_model(), then the value returned is 
as saved in the Model Catalog.
show_query(self)
Function to return the underlying SQL query.
When model object is created using retrieve_model(), then None is returned.