Teradata Package for R Function Reference | 17.20 - SVMPredict - Teradata Package for R - Look here for syntax, methods and examples for the functions included in the Teradata Package for R.

Teradata® Package for R Function Reference

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for R
Release Number
17.20
Published
March 2024
Language
English (United States)
Last Update
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
Product Category
Teradata Vantage

SVMPredict

Description

The td_svm_predict_sqle() function uses the model generated by the function td_svm_sqle() to predict target values (regression) and class labels (classification) on new input data.

Notes:

  • Standardize input features using td_scale_fit_sqle() and td_scale_transform_sqle() before using the function.

  • The function takes only numeric features. The categorical features must be converted to numeric values prior to prediction.

  • Rows with missing (NULL) values are skipped by the function during prediction.

  • For prediction results evaluation, user can use td_regression_evaluator_sqle(), td_classification_evaluator_sqle() or td_roc_sqle() function as postprocessing step.

Usage

  td_svm_predict_sqle (
      object = NULL,
      newdata = NULL,
      id.column = NULL,
      accumulate = NULL,
      output.prob = FALSE,
      output.responses = NULL,
      ...
  )

Arguments

object

Required Argument.
Specifies the tbl_teradata containing the
model data generated by td_svm_sqle() function or the of td_svm_sqle.
Types: tbl_teradata or td_svm_sqle

newdata

Required Argument.
Specifies the tbl_teradata containing the input data.
Types: tbl_teradata

id.column

Required Argument.
Specifies the name of the column that uniquely identifies an observation in the test data.
Types: character

accumulate

Optional Argument.
Specifies the name(s) of input tbl_teradata column(s) to copy to the output.
Types: character OR vector of Strings (character)

output.prob

Optional Argument.
Specifies whether the function should output the probability for each response.
Note:
Only applicable when "model_type" is 'CLASSIFICATION'.
Default Value: FALSE
Types: logical

output.responses

Optional Argument.
Specifies the class labels to output probabilities. A label must be 0 or 1.
If not specified, the function outputs the probability of the predicted response.
Note:
Only applicable when "output.prob" is TRUE.
Types: character OR vector of Strings (character)

...

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: logical

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: logical

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:

  • "<input.data.arg.name>.partition.column" accepts character or vector of character (Strings)

  • "<input.data.arg.name>.hash.column" accepts character or vector of character (Strings)

  • "<input.data.arg.name>.order.column" accepts character or vector of character (Strings)

  • "local.order.<input.data.arg.name>" accepts logical

Note:
These generic arguments are supported by tdplyr if the underlying SQLE Engine function supports, else an exception is raised.

Value

Function returns an object of class "td_svm_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", "cal_housing_ex_raw")
    
    # Create tbl_teradata object.
    data_input <- tbl(con, "cal_housing_ex_raw")
    
    # Check the list of available analytic functions.
    display_analytic_functions()
    
    # Scale "target_columns" with respect to 'STD' value of the column.
    fit_obj <- td_scale_fit_sqle(
                       data=data_input,
                       target.columns=c('MedInc', 'HouseAge', 'AveRooms',
                                       'AveBedrms', 'Population', 'AveOccup',
                                       'Latitude', 'Longitude'),
                       scale.method="STD")
    
    # Transform the data.
    transform_obj <- td_scale_transform_sqle(
                                   data=data_input,
                                   object=fit_obj$result,
                                   accumulate=c("id", "MedHouseVal"))

    # Example 1 : Predict target values (Regression) for test data using an SVM model
    #             trained by td_svm_sqle().
    
    # Train the transformed data using td_svm_sqle() where "model_type" is 'Regression'.
    svm_obj1 <- td_svm_sqle(
                  data=transform_obj$result,
                  input.columns=c('MedInc', 'HouseAge', 'AveRooms',
                                 'AveBedrms', 'Population', 'AveOccup',
                                 'Latitude', 'Longitude'),
                  response.column="MedHouseVal",
                  model.type="Regression"
                  )
    # Predict target values using regression model generated by td_svm_sqle() function.
    SVMPredict_out1 <- td_svm_predict_sqle(object = svm_obj1$result,
                                newdata = transform_obj$result,
                                id.column = "id",
                                accumulate = "MedHouseVal"
                                )
    
    # Print the result.
    print(SVMPredict_out1$result)
    
    # Example 2 : Predict target values (Classification) for test data using an td_svm_sqle model
    #             trained by td_svm_sqle().
    
    # Train the transformed data using td_svm_sqle() where "model_type" is 'Classification'.
    svm_obj2 <- td_svm_sqle(
                  data=transform_obj$result,
                  input.columns=c('MedInc', 'HouseAge', 'AveRooms',
                                 'AveBedrms', 'Population', 'AveOccup',
                                 'Latitude', 'Longitude'),
                  response.column="MedHouseVal",
                  model.type="Classification",
                  batch.size=12,
                  iter.max=301,
                  lambda1=0.1,
                  alpha=0.5,
                  iter.num.no.change=60,
                  tolerance=0.01,
                  intercept=FALSE,
                  class.weights="0:1.0,1:0.5",
                  learning.rate="INVTIME",
                  initial.data=0.5,
                  decay.rate=0.5,
                  momentum=0.6,
                  nesterov.optimization=TRUE,
                  local.sgd.iterations=1,
                  )
    # Predict target values using classification model generated by td_svm_sqle() function and
    # instance of td_svm_sqle is passed to td_svm_predict_sqle() function.
    SVMPredict_out2 <- td_svm_predict_sqle(
                        object = svm_obj2,
                        newdata = transform_obj$result,
                        id.column = "id",
                        accumulate = "MedHouseVal",
                        output.prob = TRUE,
                        output.responses = c("0", "1"))
    
    # Print the result.
    print(SVMPredict_out2$result)
    
    # Alternatively use S3 predict function to run predict on the output of
    # td_svm_sqle() function.
    
    SVMPredict_out2 <- predict(
                          svm_obj2,
                          newdata = transform_obj$result,
                          id.column = "id",
                          accumulate = "MedHouseVal",
                          output.prob = TRUE,
                          output.responses = c("0", "1"))
    
    # Print the result.
    print(SVMPredict_out2$result)