XGBoostPredict
Description
The td_xgboost_predict_sqle()
function runs the predictive algorithm based on the model generated
by td_xgboost_sqle()
. The td_xgboost_sqle()
function, also known as eXtreme Gradient Boosting,
performs classification or regression analysis on datasets.
td_xgboost_predict_sqle()
performs prediction for test input data using multiple simple trees in
the trained model. The test input data should have the same attributes as used during
the training phase, which can be up to 2046. These attributes are used to score based
on the trees in the model.
The output contains prediction for each data point in the test data based on regression
or classification. The prediction probability is computed based on the majority vote
from participating trees. A higher probability implies a more confident prediction by
the model. Majority of the trees result in the same prediction.
Notes:
The processing time is controlled by (proportional to): * The number of boosted trees used for prediction from the model (controlled by "num_boosted_trees"). * The number of iterations (sub-trees) used for prediction from the model in each boosted tree (controlled by "iter.num").
A careful choice of these parameters can be used to control the processing time.
When the boosted trees size grows more than what can fit in memory, the trees are
cached in a local spool space, which may impact the performance of the function
compared to the case when all trees fit in memory.
Usage
td_xgboost_predict_sqle (
newdata = NULL,
object = NULL,
id.column = NULL,
num.boosted.tree = 1000,
iter.num = 3,
accumulate = NULL,
output.prob = FALSE,
model.type = "REGRESSION",
output.responses = NULL,
...
)
Arguments
newdata |
Required Argument. |
object |
Required Argument. |
id.column |
Required Argument.
Types: character |
num.boosted.tree |
Optional Argument. |
iter.num |
Optional Argument. |
accumulate |
Optional Argument. |
output.prob |
Optional Argument.
Default Value: FALSE |
model.type |
Optional Argument.
Default Value: Regression |
output.responses |
Optional Argument.
Types: character OR vector of str(s) |
... |
Specifies the generic keyword arguments SQLE functions accept. Below volatile: Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:
Note: |
Value
Function returns an object of class "td_xgboost_predict_sqle"
which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator
using the name(s):result
Examples
# Get the current context/connection.
con <- td_get_context()$connection
# Load the example data.
loadExampleData("tdplyr_example", "titanic", "iris_input")
# Create tbl_teradata object.
titanic <- tbl(con, "titanic")
iris_input <- tbl(con, "iris_input")
# Check the list of available analytic functions.
display_analytic_functions()
# Example 1: This example takes titanic data as input, and generates the Regression
# model using td_xgboost_sqle() function.
# Using td_xgboost_predict_sqle() function to predict the
# fare with the Regression model generated by td_xgboost_sqle().
# Create 2 samples of input data - sample 1 will have 80% of total rows and
# sample 2 will have 20% of total rows.
titanic_sample = td_sample(df = titanic, n = c(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.
titanic_train = titanic_sample
# Create test dataset from sample 2 by filtering on "sampleid" and
# drop "sampleid" column as it is not required for scoring.
titanic_test = titanic_sample
XGBoost_out_1 <- td_xgboost_sqle(
data=titanic_train,
input.columns=c("age", "survived", "pclass"),
response.column = 'fare',
max.depth=3,
lambda1 = 1000.0,
model.type='Regression',
seed=-1,
shrinkage.factor=0.1,
iter.num=2)
# td_xgboost_predict_sqle() function predicts the result using
# generated Regression model by td_xgboost_sqle() and "newdata".
XGBoostPredict_out_1 <- td_xgboost_predict_sqle(
newdata=titanic_test,
object=XGBoost_out_1$result,
id.column='passenger',
object.order.column=c('task_index', 'tree_num',
'iter', 'tree_order'))
# Print the result.
print(XGBoostPredict_out_1$result)
# Example 2: This example takes titanic data, and generates the classification
# model using td_xgboost_sqle(). Using td_xgboost_predict_sqle()
# function to predict the fare with the classification model
# generated by td_xgboost_sqle(). 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 = td_sample(df = iris_input, n = c(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
# 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
# Training the model.
XGBoost_out_2 <- td_xgboost_sqle(
data=iris_train,
input.columns=c('sepal_length', 'sepal_width',
'petal_length', 'petal_width'),
response.column = 'species',
max.depth=3,
lambda1 = 10000.0,
model.type='Classification',
seed=-1,
shrinkage.factor=0.1,
iter.num=2)
# td_xgboost_predict_sqle() predicts the result using generated
# Classification model by td_xgboost_sqle() and XGBoost object as input.
XGBoostPredict_out_2 <- td_xgboost_predict_sqle(
newdata=iris_test,
object=XGBoost_out_2,
id.column='id',
model.type='Classification',
num.boosted.trees=3,
iter.num=2,
output.prob=TRUE,
output.responses=c('1', '2', '3'),
object.order.column=c('task_index',
'tree_num', 'iter',
'class_num', 'tree_order'))
# Print the result.
print(XGBoostPredict_out_2$result)
# Alternatively use S3 predict function to run predict on the output of
# td_xgboost_sqle() function.
XGBoostPredict_out_2 <- predict(
XGBoost_out_2,
newdata=iris_test,
id.column='id',
model.type='Classification',
num.boosted.trees=3,
iter.num=2,
output.prob=TRUE,
output.responses=c('1', '2', '3'),
object.order.column=c('task_index',
'tree_num', 'iter',
'class_num', 'tree_order'))
# Print the result.
print(XGBoostPredict_out_2$result)