| |
- DecisionForestPredict(object=None, newdata=None, id_column=None, detailed=False, terms=None, output_prob=False, output_responses=None, **generic_arguments)
- 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)
output_prob:
Optional Argument.
Specifies whether to output probabilities.
Default Value: False
Types: bool
output_responses:
Optional Argument.
Specifies responses for which to output probabilities.
Types: str OR list of strs
**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: boolean
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: 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
SQL 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 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("byom", "iris_input")
# Create teradataml DataFrames.
iris_input = DataFrame("iris_input")
# 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)
# Check the list of available analytic functions.
display_analytic_functions()
# Example 1: Train the data, i.e., create a decision forest Model with "tree_type" as classification.
formula = "species ~ sepal_length + sepal_width + petal_length + petal_width"
rft_model = DecisionForest(data=iris_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 = iris_test,
id_column = "id",
detailed = False,
terms = ["species"])
# Print the result DataFrame.
print(decision_forest_predict_out.result)
|